title: What means lne "The thread 'Win32 Thread' (0x17d0) has exited with code 2:"?
body: <p>After i closed my compiled multithread dialog based app in MFC, i saw line:</p>
  
  <pre><code>The thread 'Win32 Thread' (0x17d0) has exited with code 2
  </code></pre>
  
  <p>Instead of:</p>
  
  <pre><code>The thread 'Win32 Thread' (0x17d0) has exited with code 0
  </code></pre>
  
  <p>But all closed correctly. What does it mean?</p>
  
  <p>Edit:
  Here is thread func:</p>
  
  <pre><code>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-&gt;index;
      int index = p-&gt;curIndex;
      int direction = 1;
  
      for (int i = 0; (static_cast&lt;unsigned&gt;(startIndex + i) &gt;= 0) &amp;&amp; (static_cast&lt;unsigned&gt;(startIndex + i) &lt; ThumbnailList.size()); i += direction)
      {
          if (flagToThreadFinished)
          {
              break;
          }
  
          if (ThumbnailList.size() == 0)
          {
              AfxMessageBox(L"Here it is!!");
          }
  
          EnterCriticalSection(&amp;CriticalSection);
  
          if (ThumbnailList[startIndex + i].second-&gt;IsLoaded)
          {
              i += direction;
              continue;
          }
  
          CString path = ThumbnailList[startIndex + i].first;
  
          try
          {
              ThumbnailList[startIndex + i].second-&gt;LoadThumbNail(path);
              WPARAM a = MAKEWPARAM(startIndex + i, 0);
              ::PostMessage(p-&gt;m_hWnd, THUMBNAIL_WAS_LOADED, a, 0);
          }
          catch (...)
          {
              AfxMessageBox(L"Something bad was happend while loading!");
          }
  
          LeaveCriticalSection(&amp;CriticalSection);
  
  
          if (startIndex != p-&gt;index)
          {
              startIndex = p-&gt;index;
              i = -1;
              direction = 1;
              continue;
          }
  
  
          if (startIndex + i == ThumbnailList.size() - 1)
          {
              i = -1; 
              direction = -1;
              continue;
          }
      }
  
      return 0; 
  }
  </code></pre>
  
  <p>And here is ON_CLOSE dialog handler:</p>
  
  <pre><code>void CrMainDlg::OnClose()
  {
      flagToThreadFinished = true;
      DWORD check = WaitForSingleObject(thread, INFINITE);
      DWORD checkError = GetLastError();
  
  
      for (std::vector &lt;std::pair&lt;CString, CommonThumbnail*&gt;&gt;::iterator someIter = ThumbnailList.begin(); someIter != ThumbnailList.end(); someIter++)
      {
          if (someIter-&gt;second != nullptr)
          {
              delete someIter-&gt;second;
          }
      }
  
      ThumbnailList.clear();
      flagToThreadFinished = false;
      CDialogEx::OnClose();
  </code></pre>
  
  <p>}</p>
  
  <p>Value of GetLastError is 3435973836;</p>