From: prathamesh.s.kulkarni on
I have a MDI Application. It has a simple menu. On clicking menu
items, child forms open. Since, the loading of the form was taking
quite sometime, I have separated the loading of data by using a
background thread. Now, first the UI elements are loaded, the form is
displayed and then the data is loaded. But, still the form (UI
elements) take sometime to load and on the click of a menu item, the
menu remains for sometime in a frozen state and then the form gets
loaded. I know that this will happen and I want to just enhance user
experience by showing some waitcursor or progressbar.
On the Main form, I use the following code:
this.UseWaitCursor = true; OR toolStripProgress.Style = Marquee;
ChildForm c = new ChildForm();
c.MdiParent = this;
c.Show();

and after the form is Shown in the eventhandler C_Show()
this.UseWaitCursor = true; OR this,MDIParent.toolStripProgress.Style =
Continuos;

But nothing works...Am I doing something wrong?

-Thanks in advance.
From: Peter Ritchie [C# MVP] on
Unfortunately, neither of those methods are going to do what you want to do.

If your one-and-only UI thread is busy trying to get a form loaded it's not
available to update a progress bar, and it's not available to respond to the
WM_SETCURSOR message that asks a forum what cursor to display. In order the
the GUI to provide feedback to the user the GUI thrad can't be busy, and
since the only reason you want to provide feedback is because the GUI is busy
you're left with a catch-22.

The only solutions I can think of are to either re-design your form so it
loads quicker or break of the creation of your controls across time. i.e.
don't create all your controls when the form loads. Let the
designer-generated code create some of the controls and manually create the
rest in chunks over time (maybe a timer tick...). The drawback of that is
you can no longer reliably use the Windows Forms Designer.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#


"prathamesh.s.kulkarni(a)gmail.com" wrote:

> I have a MDI Application. It has a simple menu. On clicking menu
> items, child forms open. Since, the loading of the form was taking
> quite sometime, I have separated the loading of data by using a
> background thread. Now, first the UI elements are loaded, the form is
> displayed and then the data is loaded. But, still the form (UI
> elements) take sometime to load and on the click of a menu item, the
> menu remains for sometime in a frozen state and then the form gets
> loaded. I know that this will happen and I want to just enhance user
> experience by showing some waitcursor or progressbar.
> On the Main form, I use the following code:
> this.UseWaitCursor = true; OR toolStripProgress.Style = Marquee;
> ChildForm c = new ChildForm();
> c.MdiParent = this;
> c.Show();
>
> and after the form is Shown in the eventhandler C_Show()
> this.UseWaitCursor = true; OR this,MDIParent.toolStripProgress.Style =
> Continuos;
>
> But nothing works...Am I doing something wrong?
>
> -Thanks in advance.
>
From: prathamesh.s.kulkarni on
Thanks for responding.
I agree with what you say, indeed it is a CATCH-22 situation. But
then I am confused, as I have seen some applications doing this...
For Example in VS2005,
Click File>New>Project....and first a hour glass appears and then
appears the form/window titled "New Project". How do they do it?

and does it make sense to load a new form on a new thread (by creating
a message loop) for solving this problem?

Thanks in advance.