Вопрос

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