| 发表于:2007-03-14 06:05:521楼 得分:20 |
写一个子线程类: public class threadexample { public static bool bstop;//是否停止标志量 public static void threadproc() { while (!bstop) { console.writeline( "发送k "); thread.sleep(2000);//每两秒一次 } } 在主函数,或者启动线程的地方写: thread t = new thread(new threadstart(threadproc)); t.start(); 在需要停止的地方写: threadexample.bstop = true; 这里简化了停止逻辑,实际上也可以用mutex达到同样或者更安全的效果. | | |
|