Click to See Complete Forum and Search --> : Window controls not showing??


SilverTab
May 23rd, 2008, 12:23 AM
I have a small window (consisting of just a picturebox and a label saying "Please wait...")...

I want to display the window while my app performs a time consuming operation...(we're talking maybe 3-4 seconds here)...

So i used the following code (not exactly but to give an idea)


formWait myForm = new formWait();
myForm.Show();
callMethodDoingGruntWork();
myForm.Close();


But what happens is that, even though the form is displayed, the controls (the label and picturebox) doesn't show up... then the app locks for 3-4 seconds while the work is being done (fine with me), and the form is closed after....

I tried adding a Thread.Sleep(500) or something like that before calling the time-consuming method but it's not helping...

What can I do so the form actually has time to load before firing my time-consuming method??

(I would prefer not to use a thread since I actually *want* the application to lock while the work is being done)...

Any help would be appreciated!

Shuja Ali
May 23rd, 2008, 02:14 AM
It doesn't work that way. Wha version of framework are you using?
You could either try multithreading (1.1) or backgroundworker component to do the work on a separate thread while yous UI will not get locked.

SilverTab
May 23rd, 2008, 02:35 AM
It doesn't work that way. Wha version of framework are you using?
You could either try multithreading (1.1) or backgroundworker component to do the work on a separate thread while yous UI will not get locked.

Using .NET 2.0....

But the thing is, I want the UI to get locked... I just want to display a window first...before it gets locked....

Shuja Ali
May 23rd, 2008, 04:03 AM
Try this formWait myForm = new formWait();
myForm.Show();
myForm.Refresh();
callMethodDoingGruntWork();
myForm.Close();

Arjay
May 23rd, 2008, 05:14 AM
Using .NET 2.0....

But the thing is, I want the UI to get locked... I just want to display a window first...before it gets locked....This is a bad user experience. You may not want the user to be able to click on the controls while the work is occuring, but the user certainly should be able to move/minimize the application.

To do this, follow Shuja Ali's multithreaded or background worker approach.

With this approach, you would disable the form controls (except for maybe a 'cancel' button) and then fire off the operation.

The user wouldn't be able to click on any controls, but they would be able to move the window and/or cancel the operation.

In general, UI's shouldn't freeze while doing work.