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 { } }