Stop all application operation before ServiceHost closes or stops

175 views Asked by At

I have a class that inherits from the ServiceBase class. On the OnStop method, I stop the ServiceHost:

protected override void OnStop()
{
    if (this.serviceHost != null)
    {
         this.serviceHost.Close();
    }
}

The thing is, I want to let the application finish processing messages from the queue before the service stops (running in ConcurrencyMode.Multiple, InstanceContextMode.Single with MSMQ and WCF). Is there a way to do this? I tried to keep restarting the service while the queue is running, and sometimes I lose data (maybe some messages were running in the middle of the operation when it stopped)

1

There are 1 answers

0
Adam Straughan On

Have you tried to RequestAdditionalTime