这要用到线程同步,先创建这个线程的Event,再在你的主线程里用WaitForSingleObject,等待子线程结束后你就可以返回了。

解决方案 »

  1.   

    一种方法,供参考:
    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;
    }
      

  2.   

    稍稍修改一下楼上的程序
    WaitMutiObject和WaitSingleObject可以直接等待线程结束
      

  3.   

    这种方法我试过,如下程序:
    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(...),
    根本不去执行新开的线程里的东西,也就是说一直没有为新开的线程分配时间去执行。
      

  4.   

    用::CreateThread,返回一个线程handle,然后你在主线程里WaitForSingleObject(handle, INFINITE),OK?