PeekMessage/GetMessage switching in C#

J

JR

Hi folks,

How can I implement the following in C#?

while(AppExitFlag == false)
{
if(AppPausedFlag == true)
{
GetMessage();
// Process messages.
}
else
{
if(PeekMessage())
{
// Process messages.
}

// Do stuff...
}
}

I have a feeling you're gonna tell me this is impossible, I hope you tell me
I'm wrong. :)

John.
 
J

JR

Hi folks,

Heh, typical as soon as I write this I think of a solution:

OnApplicationIdleEvent()
{
while(AppPausedFlag == false)
{
// Do stuff.
Application.DoEvents();
}
}

static void Main()
{
Application.Run(new Form1());
}

This seems to work... Caveats anyone?

John.
 
C

Chris Taylor

Hi,

The only change I would make to your code is to remove the while loop and
thus the requirement to call Application.DoEvents(), this would I believe be
more friendly to the primary message pump.

OnApplicationIdleEvent()
{
if (AppPausedFlag == false)
{
// Do stuff.
}
}

If you want the system to be more responsive, especially if your Dostuff
takes significant amount of processing time, it might be an option to create
a background thread to perform the work. And you can control the thread with
synchronization objects.

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top