How to initialize application in a different thread?

  • Thread starter Thread starter Julia
  • Start date Start date
J

Julia

Hi,

My application need to do some initialization before it can be used
I want to display a form with the status of initialization for example:

"connection to data base..."
"loading settings....."
"registering user..."

etc...

I am thinking about using Thread.QueueUserWorkItem
to run each method
and in the end of each Thread function to Queue the next method
is this a right way?

thanks.
 
I'd spawn another thread (by creating a Thread instance and calling Start). Then have the thread report its progress via Form.BeginInvoke

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<u#VX1#[email protected]>

Hi,

My application need to do some initialization before it can be used
I want to display a form with the status of initialization for example:

"connection to data base..."
"loading settings....."
"registering user..."

etc...

I am thinking about using Thread.QueueUserWorkItem
to run each method
and in the end of each Thread function to Queue the next method
is this a right way?

thanks.




---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004



[microsoft.public.dotnet.languages.csharp]
 
If you mean this will be on a splash screen before the app starts, it's
probably reasonable to use the main thread since you can't do anything until
it finishes anyhow.

But - if you did want to make this multi-threaded, I'd have a class for the
initialization procedure and have it fire events at significant events.
 
Julia said:
My application need to do some initialization before it can be used
I want to display a form with the status of initialization for example:

"connection to data base..."
"loading settings....."
"registering user..."

etc...

I am thinking about using Thread.QueueUserWorkItem
to run each method
and in the end of each Thread function to Queue the next method
is this a right way?

Why use the thread pool? Just start a single separate thread to do all
the initialisation, reporting back to the UI with Control.Invoke to
give progress.
 
Hi, Julia.
If all those tasks (connect database, load setting ...) have to run one
after another (as implied by the way you plan to run them through the thread
pool), there is really no need to put them into the thread pool. If you just
wanna keep the application's response time short when the initialization is
under way, may be you can just start a new thread to perform all those tasks
one by one.

Best Regards
Ming Chen
 
Hi,

I think that the others post have all the answer that you need, if you need
the code just drop me a line

cheers,
 
Hi

You can put all the methods immediately by Thread.QueueUserWorkItem because
although there are max of 25 threads, all other methods will be put in the
queue and as soon as a thread is ready it will get the method from queue. You
can use an event which is signaled at the end of work of all threads,
informing the form that application can work now.
 
Back
Top