Results 1 to 4 of 4

Thread: [2005] Hide Slow Form Start

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    [2005] Hide Slow Form Start

    I'm connecting to a database and creating a dataset during the Form load event. When I start the application it appears that nothing is happening for about 30 seconds then the form appears. This is due to creation of the dataset. I moved the database connection and dataset fill into the form shown event. This allows the user to see the form immediately but none of the controls are painted until after the database stuff is complete.

    I've tried using a thread but because of my limited knowledge of OOP I'm getting lost. I need to use data from textboxes to create my connection string. If I place the database stuff in a thread and try to access any object on my form, I get an error that I can't access the data without explicitly creating an instance of the class.

    I tried this and it eliminated the error but, of course, the data that was loaded during the load event was available. i.e text boxes were empty and radio buttons were not selected.
    vb Code:
    1. Dim frm as New myForm
    2. frm = myForm
    Last edited by campster; Apr 17th, 2007 at 07:40 AM. Reason: Added [2005] to title

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Hide Slow Form Start

    Is this the startup form? If so then you might like to simply use a splash screen.

    If not then you certainly can use multi-threading. If you're using VB 2005 (please always specify) you can use a BackgroundWorker to ease the pain. Otherwise there are numerous examples already posted on the forum using delegation to access control members from worker threads. Search for invokerequired and you'll find them, because that property is always used when delegating across threads.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Hide Slow Form Start

    There's another cheating solution that I am using on a PDA. You'll have to decide whether this is acceptable to the user, or if it will simply piss them off completely:

    Open an instance of the form where the DB stuff doesn't happen, then open an instance of the form where it does. Have the two forms in the exact location, so that when the second form is ready to show, the first form can simply disappear, leaving the second form (which is identical) in its place.

    In the case of my PDA program, the form only showed a list on startup, so I saved the list into a file on shutdown, and in the first form (the dummy form), I read the list from the file (very fast, as it is only a few items), and show that. It looks like the list is there, while the real form is loading in the background. The two forms are not identical, as the dummy form doesn't have two critical buttons, but since all the user wants to do is see that list, they have the list, and have the real form only four seconds later. This cut my apparent start time from 6s down to 2s, which is significant. The cost was that the true start time (time till the real form displayed) was increased from 6s to 7s.

    It's a cheat, but just remember: "It doesn't matter what is really happening, it only matters what the user THINKS is happening."
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Re: [2005] Hide Slow Form Start

    Thanks for the the responses. I decided to use the background worker because I need to use it for another issue on the same UI as well.

    It was pretty painless to implement and seems to do what I want. The database is only associated to one button on the form so I simply disable this button until the DB is loaded. The user can utilize the rest of the UI while the DB is loaded.

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