1. 程式人生 > >C# 線程 正確使用Thread.Join()停止方式

C# 線程 正確使用Thread.Join()停止方式

join() dst 否則 dstat read oid cep reading void

/// <summary>
/// 停下線程
/// </summary>
private void MyStopTask()
{
new Action(() => {
if (thread != null)
{
while (thread.ThreadState != System.Threading.ThreadState.Stopped)//必須等線程完全停止了,否則會出現沖突。
{
try
{
buttonFun("登 錄");
thread.Join();
Thread.Sleep(2000);

}
catch (Exception ex)
{

}
}

}
}).BeginInvoke(null, null);

}

C# 線程 正確使用Thread.Join()停止方式