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.

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top