|
-
May 23rd, 2008, 12:23 AM
#1
Window controls not showing??
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)
Code:
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!
-
May 23rd, 2008, 02:14 AM
#2
Re: Window controls not showing??
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.
-
May 23rd, 2008, 02:35 AM
#3
Re: Window controls not showing??
 Originally Posted by Shuja Ali
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....
-
May 23rd, 2008, 04:03 AM
#4
Re: Window controls not showing??
Try this
Code:
formWait myForm = new formWait();
myForm.Show();
myForm.Refresh();
callMethodDoingGruntWork();
myForm.Close();
-
May 23rd, 2008, 05:14 AM
#5
Re: Window controls not showing??
 Originally Posted by SilverTab
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|