public override void OnStop() { Trace.TraceInformation("WorkerRole is stopping"); this.cancellationTokenSource.Cancel(); this.runCompleteEvent.WaitOne(); if (id == 0) { jobServer.CloseInternalService(); } else if (id == 1) { jobServer.CloseExternalService(); } else { Trace.WriteLine("Instance was never used"); } base.OnStop(); Trace.TraceInformation("WorkerRole has stopped"); }