functionA()
{
......//some other code
functionB();
......//some other code}functionB()
{
init_code();
.....
hHANDLE = CreateThread(NULL, 0, functionC, NULL, 0, &dwThrdID)
}functionC()
{
.......
deal_with_something(); //some error will be happen in the process by exterior cause
.......
}我想在functionC()错误发生后返回到functionA()从新执行
怎么办呢?

解决方案 »

  1.   

    functionC出现错误时向functionA的调用端发送一消息.或者通过事件来实现。
      

  2.   

    异常处理。
    try{functionC()}
    catch(...)
    {functionA()}
      

  3.   

    直接在functionC中制止线程以后,发送消息给主线程(界面)。然后在消息处理函数中调用functionA。
      

  4.   

    我想是否可以在function B中调用GetThreadExitCode获得返回代码,再将其返回给function Avoid FuncA()
    {
         for(;;)
         {         //some codes here
             if(FuncB()) //Test the return code
               ...//some codes here
          }
    }DWORD FuncB()
    {
       DWORD  dwThreadRtnCode;
        CreateThread(FuncC);
        dwThreadRtnCode = GetThreadExitCode(..)
        if(dwThreadRtnCode==STILL_ACTIVE)
           ....
       else
          return dwThreadRtnCode;
    }static Unit funcc()
    {
        //return 1 if some error caused otherwise return 0
    }
      

  5.   

    在线程函数中使用_endthreadex( 0 );终止线程,然后调用AfxGetMainWnd()->GetSafeHwnd获得主窗口的Hwnd,使用::SendMessage(hWnd,WM_YOURMESSAGE,....)给主框架发消息,然后在主框架中响应自定义消息,调用functionA。