c++builder XE8 線程 Thread

 thread Thread  c++builder XE8 / RAD 10 Settlephp

 

delphijava

TThread.CreateAnonymousThread(MyMethod).Start;

 

 TThread.Synchronize(TThread.CurrentThread, GetImage);//Synchronize阻塞執行同步c++

匿名線程中調用單擊事件
    TThread.CreateAnonymousThread(
      procedure()
      begin
        Button1.Click();
      end).Start;

 sql

get CreateAnonymousThread handlerapp

 Thread := TThread.CreateAnonymousThread(My_Own_Procedure); jsp

Thread.OnTerminate := MyThreadTerminated; 函數

Thread.Start;ui

https://forums.embarcadero.com/thread.jspa?threadID=171738this

 

TThread.Synchronize (TThread.CurrentThread,
  procedure ()
  begin
  end);
  end);

匿名線程,函數線程spa

void __fastcall TForm3::GetImage()
{
;
}

void __fastcall TForm3::Button1Click(TObject *Sender)
{
TThread::Synchronize(TThread::CurrentThread, GetImage);

}

上面的寫法並非建立新線程。也不是匿名線程的用法,達不到線程的效果。

是否是之前的TThread.CreateAnonymousThread

最先是這樣http://blog.csdn.net/luozhuang/article/details/29827763

c++匿名線程,XE8也沒有官方的實例,RAD 10 Settle纔有了。

    TThread::CreateAnonymousThread([this]
    {
        if (!BluetoothLE1->DiscoveredDevices->Items[ListBox1->ItemIndex]->DiscoverServices())
        {
            TThread::Synchronize(NULL, [this]
            {
                ListBox2->Items->Add("- Discover services not allow");
                ListBox1->Enabled = true;
            });
        }
    })->Start();

 

    TThread::CreateAnonymousThread(AnonymousLambda(&this->SampleDownload))->Start();

 

簡化版匿名線程

    TThread::CreateAnonymousThread([this]
    {
        TThread::Synchronize(NULL, [this]
        {
            Caption = Now();
Sleep(5000);
Caption = "end"; }); })
->Start();

匿名線程調用函數,這個就比較好用了。只能在新版編譯器bcc32c使用,bcc32不支持語法。

void __fastcall TForm3::GetImage()
{
    this->Caption = Now();
    Sleep(5000);
//Query->ExecSQL();執行sql或存儲過程
//Query->Open();
Caption = "end";
} 

void __fastcall TForm3::Button1Click(TObject *Sender)
{
TThread::CreateAnonymousThread([
this] {GetImage();})->Start();
}

 

    TThread::CreateAnonymousThread([this](){
        TThread::Synchronize(TThread::CurrentThread, [this]()
        {
            Button1->Click();
        });
    })->Start();

 

 

看原始定義參數是_di_TProc,還有下面這種寫法

TTask::Run( _di_TProc(new TCppTask(5000, MoveUpAnim, Button1)) );

http://community.embarcadero.com/index.php/blogs/entry/spinning-icons-to-visually-queue-load-states-using-true-type-font-pack-font-awesome

http://blog.appmethod.com/spinning-icons-to-visually-queue-load-states-using-true-type-font-pack-font-awesome

 

CurThread: TThreadID;

CurThread := GetCurrentThreadID;

 

界面 無延遲無卡頓,用clang編譯器

void __fastcall TForm1::Button1Click(TObject *Sender)
{

    TTask::Run([]()
        {
            Sleep(2000);
            ShowMessage("aaa");
        }

    );
}
相關文章
相關標籤/搜索