Query on Windows Service - Should I spawn off a new thread ? ...

  • Thread starter Thread starter Denzil
  • Start date Start date
D

Denzil

Hi...

I have written a Windows Service (in C#) which does the following when
it starts up...

1 - Reads a lookup file to load startup parameters.
2 - Makes a DataBase call.
3 - Creates 'x' nos. of files and copies them to a network share
(remote server).
4 - Exits the OnStart/ OnContinue Event.

1 to 4 all actions are in sequence... serial...

Now point 3 (above) can take up a lot of time (say 2 minutes) and all
this while in the SCM (Service Control Manager) the service is still
starting. What I need is that the serivce should only initiate the DB
& create file actions and should not bother about DB & file copy
completion and proceed with EXITING the OnStart event.

Whats the best way to achieve this...

What I had in mind was to spawn off a seperate thread from the
OnStart/ OnContinue event to process the DataBase and Network file
copy actions ? Is there a better approach to achieve this...

Any suggestions/ pointers will be appreciated. Thanks for your time...
Cheerz,
Denzil
 
Hi,
I suppose you can use an async delegate to start off step 3 asynchronously,
instead of you spawning another thread yourself. This will (or may) create a
new thread for you, off the .NET thread pool.
 
Back
Top