469,645 Members | 1,634 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

Delay starting Win Service

I have a Windows Service and in the OnStart, I am
initializing the BusinessLayer Object and calling a method
of the object, which normally takes about 10 mts to finish
execution.

Now when I start the Service from Administrative Tools
services, it shows starting and after sometime throw error
that the service does not respond in time and the ststus
is shown as "starting". However during this time, the
BisObject is doing its job and finally when it is done the
status shows as started.

Is OnStart the right place to call the BisObject. Is there
a better way of doing this. May be a new thread for the
BisObject. In which case, How do I close that thread. What
is the best prctice to follow in this situation.

Thanks,

Rajesh Abraham Chacko
Nov 15 '05 #1
2 3194
As you said, start a new thread from OnStart. You don't need to do anything
special to close the thread, just let it do its job in thread's Start()
method.

Eliyahu

"Rajesh Abraham" <ch******@hotmail.com> wrote in message
news:02****************************@phx.gbl...
I have a Windows Service and in the OnStart, I am
initializing the BusinessLayer Object and calling a method
of the object, which normally takes about 10 mts to finish
execution.

Now when I start the Service from Administrative Tools
services, it shows starting and after sometime throw error
that the service does not respond in time and the ststus
is shown as "starting". However during this time, the
BisObject is doing its job and finally when it is done the
status shows as started.

Is OnStart the right place to call the BisObject. Is there
a better way of doing this. May be a new thread for the
BisObject. In which case, How do I close that thread. What
is the best prctice to follow in this situation.

Thanks,

Rajesh Abraham Chacko

Nov 15 '05 #2
Rajesh,

You are on the right track with the thread idea. The OnStart must
finish within the alloted time so you shouldn't put any processing
code there.

I've seen this problem handled two ways. The first and most
straightforward is to instantiate an object in the OnStart and spawn a
new thread using a method of this main object. This will allow the
OnStart to complete in a timely fashion.

The second method is to create a timer object and set it to expire
once with a very short time. You can then put the processing code in
the elapsed event. This will allow the OnStart to complete. Behind
the scenes, the processing of the timer runs on a separate system
thread and because an event raised in a thread will be handled in that
thread no matter in which object it is defined, the elapsed event will
run in the system thread as well. This approach is actually doing the
same thing as the first approach, it is just hiding the threads.

Hope this helps
"Rajesh Abraham" <ch******@hotmail.com> wrote in message news:<02****************************@phx.gbl>...
I have a Windows Service and in the OnStart, I am
initializing the BusinessLayer Object and calling a method
of the object, which normally takes about 10 mts to finish
execution.

Now when I start the Service from Administrative Tools
services, it shows starting and after sometime throw error
that the service does not respond in time and the ststus
is shown as "starting". However during this time, the
BisObject is doing its job and finally when it is done the
status shows as started.

Is OnStart the right place to call the BisObject. Is there
a better way of doing this. May be a new thread for the
BisObject. In which case, How do I close that thread. What
is the best prctice to follow in this situation.

Thanks,

Rajesh Abraham Chacko

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by Doug Thews | last post: by
4 posts views Thread by Jeremy S | last post: by
7 posts views Thread by T Perkins | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.