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

时间:2018-12-22 20:27:45   收藏:0   阅读:676

/// <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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!