/// <summary> /// BeginShutdown initiates the termination of the Acd Agent Match Maker. /// </summary> internal IAsyncResult BeginShutdown(AsyncCallback callback, object state) { ShutdownAsyncResult asyncResult = new ShutdownAsyncResult(callback, state, this); bool firstTime = false; lock (_syncRoot) { if (_matchMakerState < MatchMakerState.Terminating) { firstTime = true; this.UpdateState(MatchMakerState.Terminating); } else if (_matchMakerState == MatchMakerState.Terminating) { _listOfShutdownAsyncResults.Add(asyncResult); } else if (_matchMakerState == MatchMakerState.Terminated) { asyncResult.SetAsCompleted(null, true); } } if (true == firstTime) { ThreadPool.QueueUserWorkItem((waitState) => { var tempAr = waitState as ShutdownAsyncResult; tempAr.Process(); }, asyncResult); } return(asyncResult); }
/// <summary> /// Initiates the portal shutdown. /// </summary> internal IAsyncResult BeginShutdown(AsyncCallback userCallback, object state) { var shutdownAsyncResult = new ShutdownAsyncResult(userCallback, state, this); lock (_syncRoot) { if (_portalState < PortalState.Draining) { _logger.Log(String.Format("AcdPortal:AcdPortal {0} is draining.", this.Uri)); //Entering Draining and setting the endpoint Draining Mode. try { _endpoint.BeginDrain(sd => { _endpoint.EndDrain(sd); }, null); } catch (InvalidOperationException ivoex) { _logger.Log("AcdPortal: the endpoint is not in the right state for draining.", ivoex); } this.UpdatePortalState(PortalState.Draining); //verify if there is anything to drain if (_sessions.Count == 0) { //process the async result right away ThreadPool.QueueUserWorkItem((waitState) => { var tempAr = waitState as ShutdownAsyncResult; tempAr.Process(); }, shutdownAsyncResult); } _shutdownAsyncResult = shutdownAsyncResult; } else if (_portalState == PortalState.Terminated) { //completes the request synchronously shutdownAsyncResult.SetAsCompleted(null, true); } else if (_portalState == PortalState.Draining || _portalState == PortalState.Terminating) { _listOfShutdownAsyncResults.Add(shutdownAsyncResult); } } return(shutdownAsyncResult); }
public IAsyncResult BeginShutdown(AsyncCallback userCallBack, object state) { var asyncResult = new ShutdownAsyncResult(userCallBack, state, this); bool firstTime = false; lock (_syncRoot) { if (_acdPlatformState < AcdPlatformState.Terminating) { this.UpdateAcdPlatformState(AcdPlatformState.Terminating); firstTime = true; } else if (_acdPlatformState == AcdPlatformState.Terminating) { _listOfShutdownAsyncResults.Add(asyncResult); } else if (_acdPlatformState == AcdPlatformState.Terminated) { asyncResult.SetAsCompleted(null, true); return(asyncResult); } } if (firstTime == true) { UnregisterForPlatformAutoProvisioningEvents(); ThreadPool.QueueUserWorkItem((waitState) => { var tempAr = waitState as ShutdownAsyncResult; tempAr.Process(); }, asyncResult); } return(asyncResult); }