多线程的问题。
{ ... labPK->Text="排课开始"; //新线程 ThreadStart^ ts=gcnew ThreadStart(this,&Form1::Start); t=gcnew Thread(ts); t->Start(); //Start(); //开始排课 //t->Join(); //while(t->IsAlive); t->ThreadState; //if(startstate)//等待线程结束 labPK->Text="完毕!"; ... }private:Void Start() { ... }
delegate void SetTextCallback(String^ text);private: void SetText(String^ text) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (labPK->InvokeRequired) { SetTextCallback^ d = gcnew SetTextCallback(this,&Form1::SetText); labPK->Invoke(d, gcnew array<Object^>{ text }); } else { labPK->Text = text; } }//设置进度条 delegate void Setpb(int value); private:Void SetpbPK(int value) { if(value<=pbPK->Maximum) if(pbPK->InvokeRequired) { Setpb ^pb=gcnew Setpb(this,&Form1::SetpbPK); pbPK->Invoke(pb,gcnew array<Object^>{ value }); } else { pbPK->Value++; } }