TThread::Terminate - C++ Builder

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


头文件:#include
命名空间:System::Classes
类:TThread
访问权限:public:
函数原型:

void __fastcall Terminate(void);

Terminate 是 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::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 ➙ Terminate

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