线程问题?来者有分。
hnwlk 2003-08-01 10:27:55 win2k professional下的程序中使用线程,创建后线程就附running_num=0,
并Star(),star的线程内容大概如下;
private void my_thread()
{
if(running_num==0)
{
end_work=true;
no_work=true;
running_num++;
this.my_thread.Suspend();
}
while(true)
{
end_work=false;
no_work=false;
//处理函数......
end_work=true;
no_work=true;
this.my_thread.Suspend();
}
}
在timer1控件中根据end_work和no_work的值来进行Resume()和Suspend(),如下:
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if(end_work==true && no_work==true)
{
this.my_thread.Suspend();
this.statusBarPanel2.Text="工作状态:空闲";
}
if(e.SignalTime.Second%15==0 && end_work==true && no_work==true)
{
no_work=false;
end_work=false;
this.statusBarPanel2.Text="正在处理....";
this.my_thread.Resume();
if(running_num<10) running_num++;
else running_num=1;
}
}
但关闭程序后,在win2k的windows任务管理器中还有此程序在运行,没有完全退出,
如不使用线程就可完全退出。若是使用线程应如何完全退出?因为这个程序只能运行
一个实例,在程序的加载时就判别有无程序在运行。