CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2008
    Posts
    27

    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!

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    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.

  3. #3
    Join Date
    May 2008
    Posts
    27

    Re: Window controls not showing??

    Quote 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....

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Window controls not showing??

    Try this
    Code:
    formWait myForm = new formWait();
    myForm.Show();
    myForm.Refresh();
    callMethodDoingGruntWork();
    myForm.Close();

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Window controls not showing??

    Quote 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
  •  





Click Here to Expand Forum to Full Width

Featured