Processing windows messages while looping in C#

Posted on 2005-03-16
Medium Priority
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))

How to do this in C# ??
Question by:MortenAH
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
            base.WndProc(ref m);

That'll do the trick.

Author Comment

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.


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


LVL 48

Accepted Solution

AlexFM earned 750 total points
ID: 13563153

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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