c# - No overload for matches delegate 'System.Timers.ElapsedEventHandler' -


i reading article: http://www.c-sharpcorner.com/uploadfile/naresh.avari/develop-and-install-a-windows-service-in-c-sharp/ playing windows services encountered little problem due lack of knowledge. in part of code:

 protected override void onstart(string[] args)     {         timer1 = new timer();         this.timer1.interval = 10800;          this.timer1.elapsed += new system.timers.elapsedeventhandler(this.timer1_tick);         timer1.enabled = true;     }      private void timer1_tick()     {        //some code here     }      protected override void onstop()     {         timer1.enabled = false;       //some code here      } 

the this.timer1.elapsed += new system.timers.elapsedeventhandler(this.timer1_tick); gives:

error 1 no overload 'timer1_tick' matches delegate 'system.timers.elapsedeventhandler'

i wonder why since many people don't have problem example?

an event nothing else multicast delegate. , method signature not match delegate signature, in case elapsedeventhandler delegate.

you have change code:

 protected override void onstart(string[] args) {     timer1 = new timer();     this.timer1.interval = 10800;      this.timer1.elapsed += new system.timers.elapsedeventhandler(this.timer1_tick);     timer1.enabled = true; }  private void timer1_tick(object sender, elapsedeventargs elapsedeventarg) {    //some code here }  protected override void onstop() {     timer1.enabled = false;   //some code here  } 

you instead of:

this.timer1.elapsed += new system.timers.elapsedeventhandler(this.timer1_tick); 

do this:

timer.elapsed += this.timer1_tick; 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -