MortenAH
asked on
Processing windows messages while looping in C#
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# ??
ASKER
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
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.