// Token: 0x060001A2 RID: 418 RVA: 0x00008D28 File Offset: 0x00006F28
 private void SubmitTask(NspiDispatchTask task)
 {
     this.CheckShuttingDown();
     if (!UserWorkloadManager.Singleton.TrySubmitNewTask(task))
     {
         ExTraceGlobals.NspiTracer.TraceError((long)task.ContextHandle, "Could not submit task");
         throw new ServerTooBusyException("Unable to submit task; queue full");
     }
 }
        // Token: 0x060001A5 RID: 421 RVA: 0x00008FA8 File Offset: 0x000071A8
        private ICancelableAsyncResult BeginWrapper(string methodName, CancelableAsyncCallback asyncCallback, object asyncState, bool rundownContextOnFailure, Func <NspiContext, NspiDispatchTask> beginDelegate, Func <NspiContext> contextFactory)
        {
            int contextHandle = 0;
            ICancelableAsyncResult asyncResult = null;

            NspiAsyncDispatch.ConditionalExceptionWrapper(ExTraceGlobals.NspiTracer.IsTraceEnabled(TraceType.DebugTrace), delegate
            {
                bool flag = false;
                FailureAsyncResult <NspiStatus> failureAsyncResult = null;
                try
                {
                    this.CheckShuttingDown();
                    try
                    {
                        using (DisposeGuard disposeGuard = default(DisposeGuard))
                        {
                            NspiContext nspiContext           = contextFactory();
                            contextHandle                     = ((nspiContext != null) ? nspiContext.ContextHandle : 0);
                            NspiDispatchTask nspiDispatchTask = beginDelegate(nspiContext);
                            disposeGuard.Add <NspiDispatchTask>(nspiDispatchTask);
                            asyncResult = nspiDispatchTask.AsyncResult;
                            this.SubmitTask(nspiDispatchTask);
                            disposeGuard.Success();
                        }
                        flag = true;
                    }
                    catch (FailRpcException ex)
                    {
                        failureAsyncResult = new FailureAsyncResult <NspiStatus>((NspiStatus)ex.ErrorCode, new IntPtr(contextHandle), ex, asyncCallback, asyncState);
                        asyncResult        = failureAsyncResult;
                    }
                    catch (NspiException ex2)
                    {
                        failureAsyncResult = new FailureAsyncResult <NspiStatus>(ex2.Status, new IntPtr(contextHandle), ex2, asyncCallback, asyncState);
                        asyncResult        = failureAsyncResult;
                    }
                    if (failureAsyncResult != null && !ThreadPool.QueueUserWorkItem(NspiAsyncDispatch.FailureWaitCallback, failureAsyncResult))
                    {
                        failureAsyncResult.InvokeCallback();
                    }
                    ExTraceGlobals.NspiTracer.TraceDebug <string, int>(0, 0L, "{0} succeeded. ContextHandle={1}", methodName, contextHandle);
                }
                finally
                {
                    if (!flag && rundownContextOnFailure && contextHandle != 0)
                    {
                        this.ContextHandleRundown(new IntPtr(contextHandle));
                    }
                }
            }, delegate(Exception exception)
            {
                ExTraceGlobals.NspiTracer.TraceDebug <string, int, Exception>(0, 0L, "{0} failed. ContextHandle={1}, Exception={2}.", methodName, contextHandle, exception);
            });
            return(asyncResult);
        }
        // Token: 0x060001A7 RID: 423 RVA: 0x00009234 File Offset: 0x00007434
        private NspiStatus EndWrapper(string methodName, ICancelableAsyncResult asyncResult, bool rundownContextOnFailure, Func <NspiDispatchTask, NspiStatus> endDelegate)
        {
            int        contextHandle = 0;
            NspiStatus nspiStatus    = NspiStatus.Success;

            NspiAsyncDispatch.ConditionalExceptionWrapper(ExTraceGlobals.NspiTracer.IsTraceEnabled(TraceType.DebugTrace), delegate
            {
                bool flag = false;
                try
                {
                    DispatchTaskAsyncResult dispatchTaskAsyncResult = asyncResult as DispatchTaskAsyncResult;
                    if (dispatchTaskAsyncResult != null)
                    {
                        NspiDispatchTask nspiDispatchTask = (NspiDispatchTask)dispatchTaskAsyncResult.DispatchTask;
                        contextHandle = nspiDispatchTask.ContextHandle;
                        using (DisposeGuard disposeGuard = default(DisposeGuard))
                        {
                            disposeGuard.Add <NspiDispatchTask>(nspiDispatchTask);
                            try
                            {
                                nspiStatus = endDelegate(nspiDispatchTask);
                            }
                            finally
                            {
                                if (nspiDispatchTask.IsContextRundown && contextHandle != 0)
                                {
                                    this.ContextHandleRundown(new IntPtr(contextHandle));
                                    contextHandle = 0;
                                }
                            }
                        }
                        ExTraceGlobals.NspiTracer.TraceDebug <string, int, NspiStatus>(0, 0L, "{0} succeeded. ContextHandle={1} NspiStatus={2}.", methodName, contextHandle, nspiStatus);
                        flag = true;
                    }
                    else
                    {
                        FailureAsyncResult <NspiStatus> failureAsyncResult = asyncResult as FailureAsyncResult <NspiStatus>;
                        if (failureAsyncResult == null)
                        {
                            throw new InvalidOperationException(string.Format("Invalid IAsyncResult encountered; {0}", asyncResult));
                        }
                        nspiStatus = failureAsyncResult.ErrorCode;
                        ExTraceGlobals.NspiTracer.TraceDebug(0, 0L, "{0} failed. ContextHandle={1} NspiStatus={2}. Exception={3}.", new object[]
                        {
                            methodName,
                            failureAsyncResult.ContextHandle.ToInt32(),
                            nspiStatus,
                            failureAsyncResult.Exception
                        });
                    }
                }
                finally
                {
                    if (!flag && rundownContextOnFailure && contextHandle != 0)
                    {
                        this.ContextHandleRundown(new IntPtr(contextHandle));
                    }
                }
            }, delegate(Exception exception)
            {
                ExTraceGlobals.NspiTracer.TraceDebug <string, int, Exception>(0, 0L, "{0} failed. ContextHandle={1}, Exception={2}.", methodName, contextHandle, exception);
            });
            return(nspiStatus);
        }