winfrom 启动后台线程 防止卡住界面及异步刷新界面的代码

            if (thread != null && thread.IsAlive)
            {
                thread.Abort();
            }
            thread = new Thread(ThreadStart);
            thread.IsBackground = true;
            thread.TrySetApartmentState(ApartmentState.STA);
            thread.Start();


private delegate void Logger(String info);
        private void AppendLog(String info)
        {
            try
            {
                if (this.InvokeRequired)
                {
                    Logger sm = new Logger(AppendLog);
                    this.Invoke(sm, info);
                }
                else
                {
                    this.rtbLog.AppendText(DateTime.Now.ToLongTimeString()+" "+info+"\r\n");
                }
            }
            catch { }
        }

 

posted on 2013-01-10 14:02  雨渐渐  阅读(320)  评论(0编辑  收藏  举报

导航