Re: Splash Screen - My Nemesis

Brady Kelly <[email protected]> Thu, 26 Jul 2007 20:04:27 +0200
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Organization Chase Software
Message-ID <[email protected]>
Fabian, thank you!  I a owe you several beers, or whatever.

I'm still determined to get a splash screen that works in all cases, but at
least some stupid users somewhere get what they want, and I hopefully get
some pocket money.

I simply show a "Please wait" label over the disabled grid until the
BackGroundWorker returns, then remove it.  My previous threading option was
getting and littered with various delegates for various controls etc.


> -----Original Message-----
> From: Discussion forum for developers using Windows Forms to build apps
> and controls [mailto:[email protected]] On Behalf Of
> Fabian Schmied
> Sent: 26 July 2007 18:43 PM
> To: [email protected]
> Subject: Re: [DOTNET-WINFORMS] Splash Screen - My Nemesis
>
> > I think now, to achieve the clients requirement of immediate feedback,
> I
> > will forego the splash screen and show the main form immediately,
> delegating
> > the database interaction to a separate thread started by the main
> form.
> >
> > Now, do I do this in the Load event, as I need the form to already be
> > visible before I spawn another thread?
>
> I think this is actually a very good approach - you can show the main
> form (disable the controls while no interaction is allowed),
> indicating your application is up and running, but provide some kind
> of visual hint that the application is busy talking to the database.
>
> About the thread spawning: don't do this yourself, use a
> BackgroundWorker instead. This is a component you can put on your
> form. Subscribe to its DoWork event and put your database code in
> there, this will be executed on a background thread.
>
> Do not access any controls from that event, just get the results of
> the database query and put it in the DoWorkEventArgs.Results member.
> If you get an error, put it in the Results member instead.
>
> Subscribe to the BackgroundWorker's RunWorkerCompleted event, it will
> be fired when DoWork has finished. Its event args will hold the Result
> you previously assigned in DoWork. You can update your UI from this
> event and either show an error message or the data retrieved from the
> database.
>
> Start the BackgroundWorker using RunWorkerAsync. If you need, you can
> pass an argument to your DoWork method. There should be no problem
> calling RunWorkerAsync from the form's OnLoad method.
>
> Shouldn't be too hard that way, and it's easy to add progress
> indicated or cancelation later, if needed (and possible).
>
> Regards,
> Fabian