如何使用窗口调度程序在不同的时间间隔内执行多个定时器....?
答
您还可以使用单一的计时器不同的时间间隔 例如:
private void Form_Load()
{
timer1.Interval = 1000; // 1 second
timer1.Start(); // Start timer, This will raise Tick event after 1 second
OnTick(); // So, call Tick event explicitly when we start timer
}
Int32 counter = 0;
private void timer1_Tick(object sender, EventArgs e)
{
OnTick();
}
private void OnTick()
{
if (counter % 1 == 0)
{
OnOneSecond();//Write your code in this method for one second
}
if (counter % 2 == 0)
{
OnTwoSecond();
}
counter++;
}
+0
感谢您的回复,但我的要求是在窗口调度程序中执行多个定时器......? – 2014-09-01 05:53:29
+0
查看此连结:http://www.codeproject.com/Articles/6507/NET-Scheduled-Timer – Komal 2014-09-01 06:19:49
是的,这是可能的。这并不是最好的选择。你的问题是广泛的这个网站。请缩小您的问题,以便我们提供答案。 – nvoigt 2014-09-01 05:44:02
请花点时间阅读http://stackoverflow.com/help/how-to-ask,然后考虑修改您的问题。 – 2014-09-01 05:47:01
你的意思是* Task * scheduler?什么是窗口调度程序?也不清楚你想在.NET中使用这个功能的哪一部分。通过API使用任务计划程序,或简单地使用计时器? – Groo 2014-09-01 05:54:55