开发者

How to call a method every 2 hours in C#

Ho开发者_Go百科w would it be possible to call a method every 2 hours in C#

For example possibly make a click event occur every 2 hours


Timer Timer.Tick Event

  1. Add Timer component to your form.
  2. Set interval to 7200000 ms (2 x 60 x 60 x 1000)
  3. Subscribe to Tick event.
  4. Call the method that you need to call. For example:

    private void timer1_Tick(object sender, EventArgs e)
    {
       button1_Click(this, EventArgs.Empty);
    }
    

I assumed you are using Windows Forms.

If you are using WPF, there is DispatcherTimer class.


Make an app which runs on a scheduled task if possible, it can then be set to call the method every 2 hours.


If your program uses forms, then a Timer can be added and configured to create a Timer.Tick Event every two hours (keep in mind Timer.Interval is in milliseconds). You can then use the Timer.Tick Event handler to call a method of your choice.


http://docs.castleproject.org/Tools.Scheduler.ashx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜