Question

I need some kind of cross-process synchronisation object that will allow me to create and initialise an object once and then close and dispose it once only when the last instance exits.

e.g. lifetime would go something like:

new Instance 1: Create and initialise object

new Instance 2: Do nothing

delete Instance 1: Do nothing

delete Instance 2: Close and dispose object

I thought a named event might work, but I can't see how it can handle the out of order creation and disposal on instances.

Was it helpful?

Solution

Use a semaphore with WaitOne() and Release() in your create and delete methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top