使用System.Threading.Timer [英] Using System.Threading.Timer
问题描述
我有一个函数,我希望每20秒调用一次,我正在使用计时器,但是它不起作用,所以我想知道是因为我在一个wrokng地方调用它!
以下是我的代码,我想知道我做错了什么?!
静态void Main()
{
System.Threading.Timer LaunchingTimer =新的System.Threading.Timer(新的TimerCallback(CreateThreads),null,0,20 * 1000);
}
静态void CreateThreads()
{
线程thread1 =新线程(新ThreadStart(LaunchApp));
线程thread2 =新线程(新ThreadStart(LaunchApp));
thread1.Start();
thread2.Start();
}
I have a function that i want it to be called every 20 seconds, i''m using a timer but it is not working, so i''m wondering is it because i''m calling it in a wrokng place !
below is my code, i want to know what i''m doing wrong ??!
static void Main()
{
System.Threading.Timer LaunchingTimer = new System.Threading.Timer(new TimerCallback(CreateThreads), null, 0, 20 * 1000);
}
static void CreateThreads()
{
Thread thread1 = new Thread(new ThreadStart(LaunchApp));
Thread thread2 = new Thread(new ThreadStart(LaunchApp));
thread1.Start();
thread2.Start();
}
推荐答案
CreateThreads必须与TimerCallback委托匹配:
静态void CreateThreads(对象状态){...}
CreateThreads must match TimerCallback delegate:
static void CreateThreads(object state){...}
这篇关于使用System.Threading.Timer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!