?
Solved

Processing windows messages while looping in C#

Posted on 2005-03-16
3
Medium Priority
?
660 Views
Last Modified: 2008-01-09

How do i handle messages (moving, repainting and so on) to a window, while doing time consuming calculating in a loop?

In c++ i just processed windows-messages by having this code somewhere in my loop:

while (GetMessage(&Msg, NULL, 0, 0))
{
  if (!IsDialogMessage(hDlg, &msg))
  {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
}

How to do this in C# ??
0
Comment
Question by:MortenAH
3 Comments
 
LVL 17

Expert Comment

by:Jesse Houwing
ID: 13559457
You need to override the following function in your control or window:

protected override void WndProc(ref Message m)
      {
            if(m.Msg == WM_...)
            {
                  // Do something here in response to messages
                  return;
            }
            base.WndProc(ref m);
      }

That'll do the trick.
0
 

Author Comment

by:MortenAH
ID: 13562995

I dont think thats quite what i need. I dont need to treat messages different, i just want to make the window able to process its message que.

example:

public void MyCalcMethod()
{
     while(reading from database)
    {
        // here some stuff is done with the db data, and the owner window will not repaint, you can not move it etc
        // beacuse the window is busy doing this while loop.

       // right here i need to get messages from the windows que and pass it to the messagehandler
   }

}

0
 
LVL 48

Accepted Solution

by:
AlexFM earned 750 total points
ID: 13563153
Application.DoEvents();
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

580 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