[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How could I block or queue a call to RunModalLoop() if a CWnd is already in a Modal State?

Posted on 2008-02-11
11
Medium Priority
?
752 Views
Last Modified: 2013-11-20
Hi, I have a CWnd derived class, say m_Wnd, that has a function foo() which calls RunModalLoop().  RunModalLoop() is used to pause the foo() function until a certain task is completed.  When this task is completed it will end RunModalLoop() and the rest of foo() will finish.  The user can make many calls to  m_Wnd->foo(), but a problem occurs when a previous call is still in RunModalLoop() and a subsequent call is made to RunModalLoop() because  m_Wnd is already in a modal state.  Is there a way to queue these calls to  foo() or RunModalLoop()?  I have beginner knowledge in threading..does this require the use of a semaphore?

Thanks
0
Comment
Question by:DrivenX
  • 5
  • 4
  • 2
11 Comments
 
LVL 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 400 total points
ID: 20869624
static bool bInProcess = false;
if(bInProcess) return;

bInProcess = true;

do long process here - run moodal loop

bInProcess = false;
0
 
LVL 1

Author Comment

by:DrivenX
ID: 20869764
Thanks for the quick reply AndyAinscow.  Sorry, I  should have not asked for a blocking solution in the title.. I have something similar implemented, but what Im truly looking for is a way to queue these calls.  Sorry about that, Thanks.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 20869819
OK.  No problems.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 86

Expert Comment

by:jkr
ID: 20869845
What are the different parameters for the modal loops?
0
 
LVL 1

Author Comment

by:DrivenX
ID: 20869937
Sorry, dont quite understand the question jkr.  RunModalLoop() does not take any parameters.

foo() takes in a URL and generates a thumbnail image of that web page. The web page is loaded in a webbrowser control and the image is captured from there.  RunModalLoop() is used to wait until the browser control is finished loading the page before capturing the web page as an image.  When the page finishes loading, RunModalLoop() quits.

If the user makes many quick successive to foo(), their will be a conflict with the RunModalLoops.  Hope that helps..
0
 
LVL 86

Expert Comment

by:jkr
ID: 20870194
>>RunModalLoop() does not take any parameters.

Yes, but when you want to "queue these calls to  foo()" there have to be some differences in the setup for these. Otherwise, you could just increment a counter and execute 'RunModalLoop()' n times until it drops to zero...
0
 
LVL 1

Author Comment

by:DrivenX
ID: 20870504
What would be a way to implement this counter?

The problem is, when one call to RunModalLoop() is running, another call cannot made to it because CWnd is already in a modal state.  A second call to RunModalLoop() causes an ASSERT error ( ASSERT(!(m_nFlags & WF_MODALLOOP)); // window must not already be in modal state ) if the previous call has not finished yet.
0
 
LVL 86

Expert Comment

by:jkr
ID: 20872209
Good question. How's your "blocking solution" set up so far? You can increment when rejecting, the problem is probably communicating the new value.
0
 
LVL 1

Author Comment

by:DrivenX
ID: 20877180
jkr: It is very similar to AndyAinscow's suggestion.  Would a list storing the parameters of the queued calls to foo() be viable?  When one call to foo() finishes, it will check if there are any more calls waiting.

But if possible, Id rather use a built in mechanism..
When a user activates an event handler (eg. generate thumbnail), it will invoke a handler function.  Does this handler function run in a separate thread? If the user activates the same handler function a second time will this run in another thread? Is it possible to use a mutex/semaphore in this case?

I have tried adding a CCriticalSection member variable to m_Wnd class and locking inside foo() but it did not work..
0
 
LVL 86

Accepted Solution

by:
jkr earned 1600 total points
ID: 20881359
Hm, getting back to the original issue, I'd rather go for the 'blockin and counting' approach (i.e. count the messages and process them later).
0
 
LVL 1

Author Closing Comment

by:DrivenX
ID: 31429941
Thanks, i needed to create a list to store the parameters as they are different for each call.  But seems to be working :)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question