When a service is told to stop, I believe it has 30 seconds before the
Service Control Manager abandons the service.
What you need to do is call the SetServiceStatus API function through
the P/Invoke layer, using the value returned from the ServiceHandle property
(it is the handle to the service which you can pass to the SetServiceStatus
function).
In your OnStop method, you would have to wait a little bit, check to see
if the update completed, then call SetServiceStatus, indicating that you are
waiting (incrementing the dwCheckPoint field of the SERVICE_STATUS
structure, so that your service knows you are doing something).
I can't recall completely, but I think there is an absolute value that
windows will wait for the service to wait, even in light of the calls to
SetServiceStatus, which if exceeded, will cause the service to be
terminated, so you might want to make sure your update completes in a timely
manner in this case.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Hi all,
>
[quoted text clipped - 12 lines]
>
> thanks.
archana - 31 Jul 2007 09:47 GMT
Hi,
thanks for your reply.
can u tell me how to do this. Because i searched on net to get
information about it to implement in framework 1.1. But of no luck.
please help me.
thanks
Nicholas Paldino [.NET/C# MVP] - 31 Jul 2007 15:45 GMT
I kind of did already in my previous post? The SetServiceStatus API is
a windows API function, and you have to call it through the P/Invoke layer.
You can get the definition from http://www.pinvoke.net most likely. You can
also most likely get the definition of the SERVICE_STATUS structure from
there as well.
The ServiceHandle property is not available in .NET 1.1, so you will
have to resort to reflection on the ServiceBase instance (the class you
derive from) to get the value. It would be an implementation detail, but
when you migrate beyond 1.1, you know it will be supported (it's a bit of a
hack, at the least in 1.1, but from what I can tell, the only way to get
what you want).

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Hi,
>
[quoted text clipped - 6 lines]
>
> thanks
Shilpa Ginode - 08 Aug 2007 08:29 GMT
Hi archana,
I saw ur thread regarding stopping the windows service.
Even I am facing the same problem.
I have created a thread in the OnStart() event of the windows service
and calling the method of the class library project(.dll).
I put the thread to sleep in the method for some period of time.(1 min)
On the OnStop() event I want to stop the service only after completion
of the work by the thread.(not in the middle.)
Did you get any solution for your problem?
If yes can you please share with me that or provide me the sample code
for the same?
Thanx in advance.
> Hi all,
>
[quoted text clipped - 10 lines]
> problem and on service i can't restart server everytime if this error
> occurs. And i want proper way to stop service.
I think the service has blown up somewhere or at some point it went into a
loop somewhere and didn't come out, which in either case it's causing the
Onstop to timeout. You need to debug your service.