private void MainThread() { ThreadStart threadStart = delegate { do { if (this.state) { if (!this.isrunning) { this.isrunning = true; this.AutoClear(); try { Getids(); } catch (Exception e) { MonitorLog.Write(LogType.Exception, Products.CRM, VersionM.Standard, "宝贝复制" + this.textBox1.Text, sellderid, "", "宝贝复制任务异常", e.ToString()); //MonitorLog.Write(LogType.Exception, Products.CRM, VersionM.Standard, "宝贝复制", sellderid, "", "全店任务异常", e.ToString()); //MonitorLog.Write(LogType.Exception, Products.QNProduct, VersionM.Standard, "好多商品-宝贝复制-全店","","", "全店任务异常", e.ToString()); //MonitorLog.Write(LogType.Exception, Products.QNProduct, VersionM.Standard, "好多商品-宝贝复制", sellderid, "", "全店任务异常", e.ToString()); this.listBox1.Items.Insert(0, "主线程出错:【" + sellderid + "】" + e.Message + "(" + DateTime.Now.ToString() + ")"); } // this.listBox1.Items.Insert(0, "【" + sellderid + "】复制成功(" + DateTime.Now.ToString() + ")"); this.isrunning = false; this.state = false; } } else { //this.button1.Text = "开启"; break; } } while (true); }; //DataTable dt = sql.ExecuteDataTable("select * from crm_productscopy where state='0' and shoptype='1'");//获取未处理的宝贝,全店复制 //foreach(DataRow dr in dt.Rows) //{ //} //Thread thread = null; //for (int i = 0; i <5; i++) //{ // thread = new Thread(threadStart); // thread.Name = "Thread" + i; // thread.SetApartmentState(ApartmentState.STA); // thread.IsBackground = true; // thread.Start(); //} Thread mainThread = new Thread(threadStart); mainThread.SetApartmentState(ApartmentState.STA); mainThread.IsBackground = true; mainThread.Start(); }