thread Thread c++builder XE8 / RAD 10 Settle
TThread.Synchronize(nil, procedure
begin
Memo1.Lines.Add('Server has NOT resume download feature');
end);
delphi
TThread.CreateAnonymousThread(MyMethod).Start;
TThread.Synchronize(TThread.CurrentThread, GetImage);//
Synchronize
阻塞执行同步
匿名线程中调用单击事件
TThread.CreateAnonymousThread(
procedure()
begin
Button1.Click();
end).Start;
get CreateAnonymousThread
handler
Thread := TThread.CreateAnonymousThread(My_Own_Procedure);
Thread.OnTerminate := MyThreadTerminated;
Thread.Start;
https://forums.embarcadero.com/thread.jspa?threadID=171738
TThread.Synchronize (TThread.CurrentThread,
procedure ()
begin
end);
end);
匿名线程,函数线程
void __fastcall TForm3::GetImage()
{
;
} void __fastcall TForm3::Button1Click(TObject *Sender)
{
TThread::Synchronize(TThread::CurrentThread, GetImage); }
上面的写法并不是创建新线程。也不是匿名线程的用法,达不到线程的效果。这个是通知主线程执行代码,也就是这个代码必须在子线程里(匿名线程也可以)里的用于更新VCL界面的,所以才用到,普通的VCL没有任何线程的代码写这个毫无意义。
是不是以前的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();
//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();
ShowMessage("aaa");
} );
}
DWORD WINAPI PollThread(LPVOID pParam)/线程函数
hThread = CreateThread ( NULL, 0, PollThread, this, 0, NULL );