private void ReturnResult(CallContext context, Response response) { if (context != null && context.CompletedAction != null) { // Deployment.Current.Dispatcher.BeginInvoke(() => context.CompletedAction(response, context.UserContext)); context.CompletedAction(response, context.UserContext); } }
private void ReturnError(CallContext context, ErrorCode errorCode) { if (context != null && context.ErrorAction != null) { // Deployment.Current.Dispatcher.BeginInvoke(() => context.ErrorAction(errorCode, context.UserContext)); context.ErrorAction(errorCode, context.UserContext); } }
private void AddQueue(CallContext callContext) { lock (CallQueue) { callContext.ID = Interlocked.Increment(ref NextID); int queueCount = CallQueue.Count; CallQueue.Enqueue(callContext); // if there was nothing in the queue, then the queue processing thread is not running // so start it now; otherwise, it's already running, so don't need to do anything if (queueCount == 0) ProcessQueueAsync(); } }
private void RemoveQueue(CallContext callContext) { lock (CallQueue) { CallContext cc = CallQueue.Dequeue(); if (callContext.ID != cc.ID) { throw new Exception( "The dequeued CallContext did not match the supplied (expected) CallContext. Responses are being handled out of the expected order."); } } }
public void SendRequest( Request request, Action<Response, object> completed, Action<ErrorCode, object> error, object context) { lock (CallQueue) { var callContext = new CallContext { CompletedAction = completed, ErrorAction = error, Request = request, UserContext = context, Operation = SocketAsyncOperation.Send, }; AddQueue(callContext); } }