110,500
社区成员
发帖
与我相关
我的任务
分享
System.Threading.AutoResetEvent autoWait = new System.Threading.AutoResetEvent(false);
bool runFlg = true;
bool isContinue = true;
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(
(obj) =>
{
autoWait.WaitOne(System.Threading.Timeout.Infinite, false);
while (runFlg)
{
if (!isContinue) break;
//To Do Something
}
}));
//按钮暂停事件中让线程暂停(线程挂起)
isContinue = false;
//按钮开始事件中让线程重新开始
autoWait.Set();
isContinue = true;
//销毁线程时
runFlg = false;
thread.Abort();
上面只是一个伪代码,楼主实现的时候,需要调整,比如autoWait变成全局变量等。