title: C++ run a function in async and not block the ui
body: <p>I have a small app that checks the dotnet framework, if it is not installed it will install it</p>
  
  <p>Now when the application starts i want to popup a gif image with something like loading and in background check the framework and install.</p>
  
  <p>the catch here is that it can not have any prerequisite to run the application</p>
  
  <p>here is what i have till now</p>
  
  <pre><code>int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                    _In_opt_ HINSTANCE hPrevInstance,
                    _In_ LPWSTR lpCmdLine,
                    _In_ int nCmdShow)
  {
         int exitCode = -1;
         showPic(hInstance);
         MessageBox(0L, L"Dotnet will installed", L"Alert", 0);
         auto fut = std::async(std::launch::async, DoWork, hInstance, lpCmdLine);
         fut.wait();
         exitCode = fut.get();
         return exitCode;
  }
  </code></pre>
  
  <p>showPic()</p>
  
  <pre><code>void showPic(HINSTANCE hInstance)
  {
      loadImage(hInstance);
      // create window
      wnd = createWindow(hInstance);
      SetWindowLong(wnd, GWL_STYLE, 0);
      ShowWindow(wnd, SW_SHOW);
  }
  </code></pre>
  
  <p>loadImage(HINSTANCE hInstance)</p>
  
  <pre><code>void loadImage(HINSTANCE hInstance)
  {
      imageDC = CreateCompatibleDC(NULL);
      imageBmp = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP1));
      imageBmpOld = (HBITMAP)SelectObject(imageDC, imageBmp);
  }
  </code></pre>
  
  <p>Now what is happening here is that the if i dont show the messagebox the picture does not load in the window, and still the window goes into not responding mode also i could not get it work with gif, only with bmp images
  any help is appriciated</p>
  
  <p>now since i wait for fut it is obvious that it will block the ui until it has the value, what is the workaround for that</p>