473,505 Members | 13,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PeekMessage/GetMessage switching in C#

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.
Nov 15 '05 #1
2 9881
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.

"JR" <moo> wrote in message
news:3f**********************@news-text.dial.pipex.com...
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.

Nov 15 '05 #2
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

--
Chris Taylor
http://www.xanga.com/home.aspx?user=taylorza
"JR" <moo> wrote in message
news:3f**********************@news-text.dial.pipex.com...
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.

"JR" <moo> wrote in message
news:3f**********************@news-text.dial.pipex.com...
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.


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
626
by: Jeff | last post by:
What is the .Net Framework equivalent of the Windows API function PeekMessage? Or any other method that will do the same thing. I simply need to check to see if there are messages waiting to be...
9
13419
by: Nadav | last post by:
Hi, I am tring to pass messages between threads, using the good old C++ I would call the GetMessage/PostThreadMessage APIs, Now, I am using C# and i can't find any equivalenty for these calls, any...
2
7838
by: Jozsef Bekes | last post by:
Hi All, I am trying to implement a general threading approach in C#, and I have faced this problem: I have the function f_main running in thread th1. I want to invoke two functions f1 and f2 in...
1
2674
by: Rajko | last post by:
Strange, very strange. I'm using CDialog to process messages form CMenu. CDialog does not enter modal state. CDialog constructor have Create() and CDialog destructor have CWnd::DestroyWindow();...
3
6443
by: John | last post by:
I get the following VB6 sample and it doesn't work in VB .Net. Can anyone help to make it work in VB .Net? Structure POINTAPI Dim x As Long Dim y As Long End Structure Structure MSG Dim...
7
3079
by: | last post by:
All, I have a MFC Mixed mode dll which is working well. I am now tring to use a regular C++ class from another DLL which has a method called GetMessage. When I link I get 2 error messages: ...
1
3554
by: Bruce | last post by:
I worte an OCX with events. In order to allow the dialog box (or whatever) to be updated by the event, I had to add a messagepump to the event. void MessagePump() { MSG msg; while...
2
6291
by: salvadorvp | last post by:
Hi, I have the following code that gives me this odd error message at a line of code inside the PEAR libraries: "Fatal error: Call to undefined function: MDB2_Driver_mssql::getMessage(). in...
1
8934
by: SeeSharp Bint | last post by:
Hi I'm using some of the definitions I found pinvoke.net for PostMessage and PeekMessage as follows public static extern bool PostMessage( HandleRef hWnd,// handle to destination window...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.