protected override void OnStop() { const int timeout = 20000; RequestAdditionalTime(timeout); var closeVasaHost = Task.Run(new Action(CloseVasaHost)); var closeVasaVersioningHost = Task.Run(new Action(CloseVasaVersioningHost)); var closeTaskManagerHost = Task.Run(new Action(CloseTaskManager)); var closeTask = Task.WhenAll(closeVasaHost, closeVasaVersioningHost, closeTaskManagerHost) .ContinueWith(t => CloseStorageConnections()); while (!closeTask.Wait(timeout / 2)) { RequestAdditionalTime(timeout); } ApplicationLog.CloseLogSession(); }