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

posted @ 2018-12-22 19:33  LuoCore  阅读(2399)  评论(0编辑  收藏  举报