TThread::Terminated - C++ Builder

C++ Builder 参考手册 ➙ System::Classes ➙ TThread ➙ Terminated


头文件:#include
命名空间:System::Classes
类:TThread
访问权限:protected:
属性定义:

__property bool Terminated = { read = FTerminated, nodefault };

Terminated 是 System::Classes::TThread 的属性,线程需要尽快停止运行。

  • Terminate 方法把 Terminated 属性置位 true,线程执行过程中发现 Terminated 属性为 true 需要尽快结束执行。

例子:

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::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 类继承关系

C++ Builder 参考手册 ➙ System::Classes ➙ TThread ➙ Terminated

你可能感兴趣的:(TThread::Terminated - C++ Builder)