Thread Terminates after 2 Minutes without any reason

Discussion in 'MFC' started by daoanhvu, Jul 1, 2010.

  1. daoanhvu

    daoanhvu New Member

    Joined:
    Jul 1, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi friends,

    I wrote a little program to practice multi-threading in VC2005. Everything seems to be OK, but it terminate after about 2 minutes with returned code 0 (0x0).

    This is my thread routine:
    Code:
    DWORD WINAPI StartMoving(void *param)
    {
    	CMyBall *p = (CMyBall*)param;
    
    	while(!isExited)
    	{
    		p->move();
    
    		//If the ball reachs bottom, top, left or right border, it will turn out
    		if((p->x < p->R)||(p->x > (rectClient.right - rectClient.left)-p->R))
    			p->vx = -p->vx;
    
    		if((p->y < p->R)||(p->y > (rectClient.bottom - rectClient.top)-p->R))
    			p->vy = -p->vy;
    
    		WaitForSingleObject(g_displayMutex, INFINITE);
    
    		InvalidateRect(g_hWnd, NULL, 0);
    		Sleep(20);
    
    		ReleaseMutex(g_displayMutex);
    	}
    	return 0;
    }
    Any explanation will be appreciated.
    Thanks
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice