Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to show a modal dialog in multithread app?

How to show a modal dialog in multithread app?

Scheduled Pinned Locked Moved C / C++ / MFC
phpcomdebuggingtutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LaoWei
    wrote on last edited by
    #1

    How to show a modal dialog in multithread app? I want to show a modal dialog in multi thread application. But when I show the dialog as the fllowing, VC shows "Debug Assertion Failed" dialog. Anyone knows how to do it? Thanks very much. CAboutDlg dlg; dlg.DoModal(); The attachment is a demo. testmultithread.zip

    R 1 Reply Last reply
    0
    • L LaoWei

      How to show a modal dialog in multithread app? I want to show a modal dialog in multi thread application. But when I show the dialog as the fllowing, VC shows "Debug Assertion Failed" dialog. Anyone knows how to do it? Thanks very much. CAboutDlg dlg; dlg.DoModal(); The attachment is a demo. testmultithread.zip

      R Offline
      R Offline
      Robert Kuster
      wrote on last edited by
      #2

      Hi LaoWei. First, there is a little bug in your CreateMultiThread:

      void CTestMultiThreadApp::CreateMultiThread()
      {
      DWORD tID;
      g_nIndex**[1]** = 0;
      ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProc, (LPVOID)&(g_nIndex**[0]), 0, &tID);
      g_nIndex
      [1]** = 1;
      ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProc, (LPVOID)&(g_nIndex**[1]**), 0, &tID);
      }

      Second, you use CreateThread in conjunction with MFC. This is dangerous. If your thread uses MFC support it should always be created via AfxBeginThread. Knowing this, you can write CreateMultiThread as follows:

      void CTestMultiThreadApp::CreateMultiThread()
      {
      DWORD tID;
      g_nIndex[0] = 0;
      AfxBeginThread((AFX_THREADPROC)afxThreadProc,(LPVOID)&(g_nIndex[0]));

      g\_nIndex\[1\] = 1;
      **AfxBeginThread**((AFX\_THREADPROC)afxThreadProc,(LPVOID)&(g\_nIndex\[1\]));
      

      }

      Now your "Debug Assertion Failed" is gone bye bye... :) RK

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups