2
如果有人能帮助我,我会很高兴。我自己是C++ Builder的新手,从来没有在C++中使用线程。T在C++ Builder中的线程
我有一个窗体内的C++ builder我想要线程,所以它不会崩溃。此时表单在完成应用程序的后台进程之前不会加载。
如果有人能帮助我,我会很高兴。我自己是C++ Builder的新手,从来没有在C++中使用线程。T在C++ Builder中的线程
我有一个窗体内的C++ builder我想要线程,所以它不会崩溃。此时表单在完成应用程序的后台进程之前不会加载。
在C++ Builder中,您应该添加一个线程对象(右键单击“project.exe”,添加新的,其他的,它位于C++ Builder文件文件夹中)。 然后,您需要添加标头include并实例化对象。
如果您对处理对象过于小心,您可以简单地使用带有函数的CreateThread函数。也许这不是最好的,但如果你没有经验,这很容易。
TForm1 *Form1;
unsigned long __stdcall my_thread_func(void *args);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner){
CreateThread(NULL,0,&my_thread_func,NULL,0,NULL); //create thread in form constructor
}
//---------------------------------------------------------------------------
// Write a function like this
unsigned long __stdcall my_thread_func(void *args){
Sleep(5000);
Form1->Caption = L"Done!!";
}
有什么更具体的,你正在努力?如果您只想了解基础知识,您可以在网上找到相关信息,例如http://www.inteldoorway.com/programming/cbuilder/threads/basics.htm – Michael 2012-07-25 15:34:11
[C++ builder中的线程]的可能重复(http://stackoverflow.com/questions/11639859/threads-in-c-builder) 。 – 2012-07-26 02:08:14
请提供一些您正在使用的代码,或者更具体地说明您想要什么... – kokbira 2012-09-11 19:37:25