public override void StartClient(GetNextRequestState state) { if (state != null) { state.Invoke(); } }
/// <summary> /// Async open the connection and start to process requests. /// </summary> public void AsyncStart(GetNextRequestState state, int serviceOperationTimeout) { BrokerTracing.TraceVerbose("[AzureServiceClient]. AsyncStart is called."); this.serviceOperationTimeout = serviceOperationTimeout; Guid clientGuid = this.ServiceClient.ClientGuid; if (Interlocked.CompareExchange(ref this.clientOpenAsync, 1, 0) == 0) { if (state != null) { lock (this.SyncObjForStateList) { // this.stateList cannot be null before BeginOpen is called. BrokerTracing.TraceVerbose("[AzureServiceClient]. AsyncStart: Add async state to the list before BeginOpen is called, client {0}", clientGuid); this.stateList.Add(state); } } BrokerTracing.TraceVerbose("[AzureServiceClient]. AsyncStart: BeginOpen the client {0}", clientGuid); ThreadPool.QueueUserWorkItem( new ThreadHelper <object>(new WaitCallback(AzureServiceClient.AsyncStartWorker)).CallbackRoot, new object[] { this, this.serviceOperationTimeout }); } else { BrokerTracing.TraceVerbose("[AzureServiceClient]. AsyncStart: BeginOpen is already called, client {0}", clientGuid); if (state != null) { lock (this.SyncObjForStateList) { if (this.stateList != null) { BrokerTracing.TraceVerbose("[AzureServiceClient]. AsyncStart: Add async state to the list after BeginOpen is called, client {0}", clientGuid); this.stateList.Add(state); } else { // if this.stateList is null, TriggerGetNextRequest is already called. BrokerTracing.TraceVerbose("[AzureServiceClient]. AsyncStart: Call GetNextRequest method, client {0}", clientGuid); state.Invoke(); } } } } }