一种方法,供参考: CEvent g_eventNotify // creates global autoreset eventsin UI thread:MyCreateThread() { AfxBeginThread(MyThreadFunction,...) WaitForSingleObject(g_eventNotify, INFINITE) }in WORKER thread: UNIT MyThreadFunction(...) { // my thread process // ... // ends of the process g_eventNotify.SetEvent(); return 0; }
这种方法我试过,如下程序: MyCreateThread() { AfxBeginThread(MyThreadFunction,...) WaitForSingleObject(g_eventNotify, INFINITE) }in WORKER thread: UNIT MyThreadFunction(...) { // my thread process // ... // ends of the process g_eventNotify.SetEvent(); return 0; }在MyCreateThread()里面,执行完AfxBeginThread后,就一直WaitForSingleObject(...), 根本不去执行新开的线程里的东西,也就是说一直没有为新开的线程分配时间去执行。
CEvent g_eventNotify // creates global autoreset eventsin UI thread:MyCreateThread()
{
AfxBeginThread(MyThreadFunction,...)
WaitForSingleObject(g_eventNotify, INFINITE)
}in WORKER thread:
UNIT MyThreadFunction(...)
{
// my thread process
// ...
// ends of the process
g_eventNotify.SetEvent();
return 0;
}
WaitMutiObject和WaitSingleObject可以直接等待线程结束
MyCreateThread()
{
AfxBeginThread(MyThreadFunction,...)
WaitForSingleObject(g_eventNotify, INFINITE)
}in WORKER thread:
UNIT MyThreadFunction(...)
{
// my thread process
// ...
// ends of the process
g_eventNotify.SetEvent();
return 0;
}在MyCreateThread()里面,执行完AfxBeginThread后,就一直WaitForSingleObject(...),
根本不去执行新开的线程里的东西,也就是说一直没有为新开的线程分配时间去执行。