什么意思lne“线程'Win32线程'(0x17d0)退出代码2:”?

时间:2013-08-23 09:15:01

标签: c++ multithreading mfc dialog

在MFC中关闭我编译的多线程对话框应用程序后,我看到了行:

The thread 'Win32 Thread' (0x17d0) has exited with code 2

而不是:

The thread 'Win32 Thread' (0x17d0) has exited with code 0

但都正确关闭了。这是什么意思?

编辑: 这是线程函数:

UINT CrMainDlg::WorkerThreadProc(LPVOID Param)
{
    if(Param == NULL)
    {
        AfxMessageBox(L"Params in thread func are equal to NULL!");
        return 0;
    }

    inputParam* p = (inputParam*)Param;
    int startIndex = p->index;
    int index = p->curIndex;
    int direction = 1;

    for (int i = 0; (static_cast<unsigned>(startIndex + i) >= 0) && (static_cast<unsigned>(startIndex + i) < ThumbnailList.size()); i += direction)
    {
        if (flagToThreadFinished)
        {
            break;
        }

        if (ThumbnailList.size() == 0)
        {
            AfxMessageBox(L"Here it is!!");
        }

        EnterCriticalSection(&CriticalSection);

        if (ThumbnailList[startIndex + i].second->IsLoaded)
        {
            i += direction;
            continue;
        }

        CString path = ThumbnailList[startIndex + i].first;

        try
        {
            ThumbnailList[startIndex + i].second->LoadThumbNail(path);
            WPARAM a = MAKEWPARAM(startIndex + i, 0);
            ::PostMessage(p->m_hWnd, THUMBNAIL_WAS_LOADED, a, 0);
        }
        catch (...)
        {
            AfxMessageBox(L"Something bad was happend while loading!");
        }

        LeaveCriticalSection(&CriticalSection);


        if (startIndex != p->index)
        {
            startIndex = p->index;
            i = -1;
            direction = 1;
            continue;
        }


        if (startIndex + i == ThumbnailList.size() - 1)
        {
            i = -1; 
            direction = -1;
            continue;
        }
    }

    return 0; 
}

这是ON_CLOSE对话框处理程序:

void CrMainDlg::OnClose()
{
    flagToThreadFinished = true;
    DWORD check = WaitForSingleObject(thread, INFINITE);
    DWORD checkError = GetLastError();


    for (std::vector <std::pair<CString, CommonThumbnail*>>::iterator someIter = ThumbnailList.begin(); someIter != ThumbnailList.end(); someIter++)
    {
        if (someIter->second != nullptr)
        {
            delete someIter->second;
        }
    }

    ThumbnailList.clear();
    flagToThreadFinished = false;
    CDialogEx::OnClose();

}

GetLastError的值为3435973836;

0 个答案:

没有答案