/// <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);
}
转载于:https://www.cnblogs.com/LuoEast/p/10162202.html
本文介绍了一种在C#中优雅地停止线程的方法,通过检查线程状态并使用Join方法确保线程完全停止,避免了因线程未完全停止而可能引发的冲突。
867

被折叠的 条评论
为什么被折叠?



