[英]C# Executing a method with intervals using system.threading.timer
Hello Lets say I have a console application, that looks like this 你好说我有一个控制台应用程序,看起来像这样
class Program
{
static void Main(string[] args)
{
}
public void DoSomething()
{
Console.WriteLine("Hello World");
}
}
} }
I wan't to execute my DoSomething method every 10'th second by using System.Threading.timer. 我不想每隔10秒使用System.Threading.timer执行我的DoSomething方法。 Can anyone give an example of how that is done? 谁能举例说明这是怎么做的?
Thanks in advance :) 提前致谢 :)
System.Threading.Timer
类的文档页面有一个冗长的好例子。
Timer timer1 = new Timer(10000);
timer1.Enabled = true;
timer1.Elapsed += new ElapsedEventHandler(timer1_Elapsed);
timer1.Start();
static void timer1_Elapsed(object sender, ElapsedEventArgs e)
{
//Do Something
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.