Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ShowDialog without Blocking Caller

Tags:

c#

.net

winforms

I have a strong named assembly.

This has been asked before...but only sort of and with a different purpose.

I have a Form base class. When the implementing class sets a property on the base class IsBusy. I want to block all interaction with the Form (setting Enabled = false is not enough - I also want to block moving, resizing, closing, etc....and I don't want my controls to look disabled when IsBusy == true) and show a popup loading form in front (a transparent, borderless form with a loading animation).

Calling ShowDialog on my loading animation form does the trick in terms of blocking interaction on the calling form...but obviously I also want the calling forms code to continue executing.

Right now I'm using new LoadingForm().Show(), then handling WndProc on my calling Form and if IsBusy == true I supress all WndProc messages...but I don't like this approach. It prevents the form from repainting too, which I don't want.

I wouldn't mind the WndProc approach so much if I knew all the different types of messages to let through to allow correct repainting while IsBusy == true...but I don't.

So, my question is:

Is there a better solution?

or

Cans someone tell what WndProc messages I should let through? Or where to find a glossary?

Thanks.

like image 970
Jeff Avatar asked Dec 01 '22 02:12

Jeff


1 Answers

I ended up BeginInvoke'ing a ShowDialog:

myForm.BeginInvoke(new Action(() => new LoadingForm().ShowDialog()));

that has the desired effect of letting code after that line continue to run and still blocking all interaction with myForm.

like image 106
Jeff Avatar answered Jan 03 '23 07:01

Jeff