having the last word in ServiceBase.OnStop()

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.
 
J

Jeff Johnson

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top