C# 线程 正确使用Thread.Join()停止方式

/// <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);
           
        }

猜你喜欢

转载自www.cnblogs.com/LuoEast/p/10162202.html