由网友(软糖)分享简介:如何才能够调用一个方法每隔2小时在C#How would it be possible to call a method every 2 hours in C#例如可能使一个点击事件发生每隔2小时For example possibly make a click event occur every 2 hours...
如何才能够调用一个方法每隔2小时在C#
How would it be possible to call a method every 2 hours in C#
例如可能使一个点击事件发生每隔2小时
For example possibly make a click event occur every 2 hours
推荐答案
定时器的 Timer.Tick事件
添加定时器
组件到窗体。
设置间隔为7200000毫秒(2×60×60×1000)
订阅勾选
事件。
通话,你需要调用的方法。例如:
Add Timer
component to your form.
Set interval to 7200000 ms (2 x 60 x 60 x 1000)
Subscribe to Tick
event.
Call the method that you need to call. For example:
private void timer1_Tick(object sender, EventArgs e)
{
button1_Click(this, EventArgs.Empty);
}
我假设你正在使用Windows窗体。
I assumed you are using Windows Forms.
如果您正在使用WPF,有 DispatcherTimer
类。
If you are using WPF, there is DispatcherTimer
class.
相关推荐
最新文章