码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-12-22 20:39:09      阅读:335      评论:0      收藏:0      [点我收藏+]

标签:invoke   使用   try   join   exce   出现   mys   top   reads   

/// <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()停止方式

标签:invoke   使用   try   join   exce   出现   mys   top   reads   

原文地址:https://www.cnblogs.com/LuoEast/p/10162202.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!