How to get status of execution of a method declared as Single Instance Mode

85 views Asked by At

I have declared my service behavior as single instance mode as stated below

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] 
public class Service : IService
{
  [OperationBehavior]
        public void DoSomething()
        {
          ...
        }
}

I want to know the execution status of DoSomething() from the client, ensuring that while it is running, no client request should call DoSomething(). Please help me to find a solution?

1

There are 1 answers

0
nvoigt On

You cannot.

If you actually have only a single instance, you could have a second method, that gives you a status. But this is a asynchronous system, if you ask whether it's busy, you get an answer... on your next call it might already be different. You could return a bool from your method and make your method return false immediately if you find out it's already running. Or you could make your method wait for all other calls to finish and then continue with it's current call. Or you could have that message just queue the work and have another service continuously working on all queued items one after another.

The point is, you need a strategy here, and you need to make that decision. Once you have made it and you implemented it and you have a specific problem doing so, fel free to come here and ask a specific question again.