I have quite a challange trying to stop an ongoing subscription. My setup is a Windows service that has a subscription og a stream with pretty many events. The Windows service is holding a domain model in memory and with some interval I would like to store that domain model to disk. To do so I call the Stop method on the EventStore and then starts to flush my memory objects to disk.
However, the subscription isn’t stopped when the Stop method is called and actually all events already fetched by my subscription is executed and that is giving me a lot of problems.
So how to I stop the subscription and wait for all pending events to finish processing?
I’ve tried added some lock mechanism in the call back functions of the subscription but it seems that I’m not always getting the “user cancelation” event and thereby I end up with a Windows service waiting forever for the lock!