C++ Builder 参考手册 ➙ System::Classes ➙ TThread ➙ WaitFor
头文件:#include <System.Classes.hpp>
命名空间:System::Classes
类:TThread
访问权限:public:
函数原型:
unsigned __fastcall WaitFor(void);
WaitFor 是 System::Classes::TThread 的成员函数,等待线程结束。
参数:
无。
返回值:
线程结束时 ReturnValue 属性的值。
例子:
class TTestThread : public System::Classes::TThread
{
private:
void __fastcall SetLabelValue(void)
{
Form1->Label1->Caption = StrToIntDef(Form1->Label1->Caption,0) + 1;
}
protected:
void __fastcall Execute(void)
{
while(!Terminated)
{
Synchronize(SetLabelValue);
Sleep(200);
}
}
};
TTestThread *lpTestThread = NULL;
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(!lpTestThread)
{
lpTestThread = new TTestThread;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(lpTestThread)
{
lpTestThread->Terminate();
lpTestThread->WaitFor();
delete lpTestThread;
lpTestThread = NULL;
}
}
相关:
- System::Classes::TThread::ReturnValue
- System::Classes::TThread::Terminate
- System::Classes::TThread::Terminated
- System::Classes::TThread::TerminatedSet
- System::Classes::TThread::FreeOnTerminate
- System::Classes::TThread::Finished
- System::Classes::TThread::Started
- System::Classes::TThread::Execute
- System::Classes::TThread::WaitFor
- System::Classes::TThread
- System::TObject
- VCL 类继承关系
C++ Builder 参考手册 ➙ System::Classes ➙ TThread ➙ WaitFor
网友评论