having the last word in ServiceBase.OnStop()

  • Thread starter Thread starter John A Grandy
  • Start date Start date
J

John A Grandy

I have implemented a Windows Service ( ServiceBase ).

My service calls a a 3rd-party lib that initializes & initiates a process
that continually provides data via a callback in my service.

In the callback, the provided data is written to files and tracking data is
written to db.

In ServiceBase.OnStop() I need to do some files/db cleanup.

I am finding that my service continues to process callbacks even after
OnStop() has been entered.

So, the sequence is :

1. start service
2. call into service
3. service initiates 3rd party lib
4. service processes callbacks
5. stop service
6. OnStop() is triggered
7. run cleanup
8. callbacks processing continue for a bit
9. service stops

So, the net result is that my cleanup can never been complete.

How do I "have the last word" before my service shuts-down ?

Thanks.
 
I have implemented a Windows Service ( ServiceBase ).

My service calls a a 3rd-party lib that initializes & initiates a process
that continually provides data via a callback in my service.

In the callback, the provided data is written to files and tracking data
is written to db.

The callback is YOUR code, right? So why not have a module-level Boolean
(i.e., a field) which you set in the Stop event handler and which your
callback checks before doing anything?
 
Back
Top