美文网首页
TThread::Terminated - C++ Builde

TThread::Terminated - C++ Builde

作者: 玄坴 | 来源:发表于2020-06-24 10:46 被阅读0次

    C++ Builder 参考手册 ➙ System::Classes ➙ TThreadTerminated


    头文件:#include <System.Classes.hpp>
    命名空间: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;
        }
    }
    

    相关:


    C++ Builder 参考手册 ➙ System::Classes ➙ TThreadTerminated

    相关文章

      网友评论

          本文标题:TThread::Terminated - C++ Builde

          本文链接:https://www.haomeiwen.com/subject/flrlohtx.html