How does one ensure only one instance of a server Add-in task

(Using the C++ or C API to create a server add-in task.)

Does anyone know of an API call (or some other technique) for a Server Add-in Task to determine if a previous instance of itself is already loaded?

So that, a second “load mytask” console command will not start another instance of the task.

(The task is our own, not a built-in one.)

– Grant

P.S.: I did search for an answer, but if you find this documented somewhere, I’d love the link/reference.

Subject: Here is what I came up with…

But, I am still looking for a better approach, if there is one.

My approach, essentially, uses the add-in task’s Message Queue as a semaphore.

At a high level:

  1. Task starts.

  2. As soon as possible, the task tries to create a Message Queue with LNNotesSession::CreateMessageQueue().

  3. a) If ERR_DUPLICATE_MQ is thrown, then (presumably) a previous instance is already running and has created a Queue. Quit this instance.

  4. b) Otherwise, open the Queue.

  5. Continue.

Though the process feels less robust then I would like, it seems to work–I can only start one instance of my task at a time.

Does anyone have a better solution/method?

– Grant