C++ Builder 參考手冊(cè) ? System::Classes ? TThread ? Terminated
頭文件:#include <System.Classes.hpp>
命名空間:System::Classes
類:TThread
訪問權(quán)限:protected:
屬性定義:
__property bool Terminated = { read = FTerminated, nodefault };
Terminated 是 System::Classes::TThread 的屬性,線程需要盡快停止運(yùn)行。
- Terminate 方法把 Terminated 屬性置位 true杨名,線程執(zhí)行過程中發(fā)現(xiàn) Terminated 屬性為 true 需要盡快結(jié)束執(zhí)行。
例子:
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;
}
}
相關(guān):
- System::Classes::TThread::Terminate
- 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 類繼承關(guān)系
C++ Builder 參考手冊(cè) ? System::Classes ? TThread ? Terminated