System.Timers.timer 这个会引发多线程并发,我需要它监督某某时间发邮件,它发了n份,如何控制这个Timer多线程????
解决方案 »
- winfrom 程序 如何保存数据?
- 有人用过axSpreadsheet控件的么?
- 不安全代码只会在使用/unsafe编译的情况下出现???
- 请问这样的DataGridView列头咋整呢?有图有真相!
- 关于水晶报表问题
- (敬请高手和志同道合者加入我们) 欢迎加入.NET高手与高手成长群:14282006 (将会非同一般)
- 新手问题:字符串问题(二),高手请进!!!!谢谢!!不好意思,没分了
- 一个remoting的问题。各位兄弟帮帮忙
- 谁知道GTK# For Linux在那下???
- 气死我了!!!!快来看看吧!
- C#在textbox中输入数据,然后插入到datagridview中
- 如何判断文本框输入的内容被修改?
{
List<Thread> threadlist = new List<Thread>();
for (int i = 0; i < 5; i++)
{
Thread th = new Thread(new ParameterizedThreadStart(Func));
threadlist.Add(th);
}
isStop = false;
for (int i = 0; i < threadlist.Count; i++)
{
threadlist[i].Start(i);
Console.WriteLine("线程"+i.ToString()+"已经启动...");
}
Timer timer = new Timer(new TimerCallback(timerFun),null,0,1000);
}
static bool isStop = true;
static Queue<string> queue = new Queue<string>();
static void Func(object obj)
{
int index = (int)obj; while (!isStop)
{
lock (queue)
{
queue.Enqueue("现在时间" + DateTime.Now.ToString());
}
Thread.Sleep(1000);
}
} static void timerFun(object obj)
{
lock (queue)
{
if (queue.Count > 0)
{
string s = queue.Dequeue();
Console.WriteLine("取出消息:" + s);
}
}
}