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. Resource Sharing issue

Resource Sharing issue

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpannouncementlearning
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.
  • G Offline
    G Offline
    georgekjolly
    wrote on last edited by
    #1

    Dear All, I have resource sharing issue in my MFC programming. Below, I will describe the scenario. I am using VC++ 6.o version I have a dialog(modeless) based application. Main dialog box has a Button( say "Button1" ) with OnButton1(), that will call member function DisplayChildDialog() I have a worker thread also, that will call DisplayChildDialog() using PostMessage() of main dialog. DisplayChildDialog() will dispaly a child dialog(modal). Child dialog's object is created locally in DisplayChildDialog(). So DisplayChildDialog() will always called from the GUI thread. Scenario: When I clicks on "Button1", OnButton1() will call a member function DisplayChildDialog() and a child dialog(modal) will appear. This time worker thread will also call DisplayChildDialog() using PostMessage() of Main dialog. When I click on "Button1" DisplayChildDialog() will also call from worker thread using PostMessage(). of the main dialog. So two dialogs will appear simultaniously. To avoid this situation I made the second caller of DisplayDialog() to enter in a MessageLoop, and will check a flag that will infrom whether the first caller has left the DisplayChildDialog() or not. I wrote the message loop in DisplayDialog() like this. DisplayDialog() { if( CChildDlg::m_bDisply == true ) { while( GetMessage( &stMsg, 0, 0, 0 )) { TranslateMessage( &stMsg ); DispatchMessage( &stMsg ); if( false == CChildDialog::m_bDisply ) { OutputDebugString( _T( "### Message loop false************************" )); return; } } } CChildDlg::m_bDisply = true; CChildDlg objChild; objChild.DoModal(); CChildDlg::m_bDisply = false; } But this will work 5 or 6 times correctly. But after that, when I clicks on "Button1", the first caller of DisplayDialog() will terminate before showing the dialog box it will just make CChildDlg::m_bDisply = true. So the second caller will enter in Message loop and never exit. I tried this too instead of above given message loop: while( CChildDlg::m_bDisply && WaitMessage()) { AfxGetApp()->PumpMessage(); } But both given same result.. Please help me.

    C 1 Reply Last reply
    0
    • G georgekjolly

      Dear All, I have resource sharing issue in my MFC programming. Below, I will describe the scenario. I am using VC++ 6.o version I have a dialog(modeless) based application. Main dialog box has a Button( say "Button1" ) with OnButton1(), that will call member function DisplayChildDialog() I have a worker thread also, that will call DisplayChildDialog() using PostMessage() of main dialog. DisplayChildDialog() will dispaly a child dialog(modal). Child dialog's object is created locally in DisplayChildDialog(). So DisplayChildDialog() will always called from the GUI thread. Scenario: When I clicks on "Button1", OnButton1() will call a member function DisplayChildDialog() and a child dialog(modal) will appear. This time worker thread will also call DisplayChildDialog() using PostMessage() of Main dialog. When I click on "Button1" DisplayChildDialog() will also call from worker thread using PostMessage(). of the main dialog. So two dialogs will appear simultaniously. To avoid this situation I made the second caller of DisplayDialog() to enter in a MessageLoop, and will check a flag that will infrom whether the first caller has left the DisplayChildDialog() or not. I wrote the message loop in DisplayDialog() like this. DisplayDialog() { if( CChildDlg::m_bDisply == true ) { while( GetMessage( &stMsg, 0, 0, 0 )) { TranslateMessage( &stMsg ); DispatchMessage( &stMsg ); if( false == CChildDialog::m_bDisply ) { OutputDebugString( _T( "### Message loop false************************" )); return; } } } CChildDlg::m_bDisply = true; CChildDlg objChild; objChild.DoModal(); CChildDlg::m_bDisply = false; } But this will work 5 or 6 times correctly. But after that, when I clicks on "Button1", the first caller of DisplayDialog() will terminate before showing the dialog box it will just make CChildDlg::m_bDisply = true. So the second caller will enter in Message loop and never exit. I tried this too instead of above given message loop: while( CChildDlg::m_bDisply && WaitMessage()) { AfxGetApp()->PumpMessage(); } But both given same result.. Please help me.

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      How can it terminate without showing the dialog and leave your flag set to true?

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

      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