我有一些线程,我想在这些线程中使用计时器的已用事件。所有计时器的已用事件应该在不同的线程中工作。
例如:
Thread thDoviz = new Thread(OntmrDoviz_Elapsed);
private static Timer tmrDoviz = new Timer(3600000);
private static void OntmrDoviz_Elapsed(object source, ElapsedEventArgs e)
{
Console.WriteLine("sdf");
}
我知道这段代码不起作用,我应该如何设置代码?
答案 0 :(得分:1)
也许你的意思是这样的:
private static Timer tmrDoviz = new Timer(3600000);
tmrDoviz.Elapsed += new ElapsedEventHandler(OntmrDoviz_Elapsed);
private static void OntmrDoviz_Elapsed(object source, ElapsedEventArgs e)
{
Thread thDoviz = new Thread(SomeOtherFunctionToRunFromThread);
thDoviz .Start();
}