protected void EnqueueCheckAndStartRequestServicingThread(GetRunspaceAsyncResult requestToEnqueue, bool useCallingThread) { bool flag = false; lock (this.runspaceRequestQueue) { if (requestToEnqueue != null) { this.runspaceRequestQueue.Enqueue(requestToEnqueue); } if (this.isServicingRequests) { return; } if ((this.runspaceRequestQueue.Count + this.ultimateRequestQueue.Count) > 0) { lock (this.pool) { if ((this.pool.Count > 0) || (this.totalRunspaces < this.maxPoolSz)) { this.isServicingRequests = true; if (useCallingThread && (this.ultimateRequestQueue.Count == 0)) { flag = true; } else { ThreadPool.QueueUserWorkItem(new WaitCallback(this.ServicePendingRequests), false); } } } } } if (flag) { this.ServicePendingRequests(true); } }
internal IAsyncResult BeginGetRunspace(AsyncCallback callback, object state) { this.AssertPoolIsOpen(); GetRunspaceAsyncResult requestToEnqueue = new GetRunspaceAsyncResult(this.InstanceId, callback, state); this.EnqueueCheckAndStartRequestServicingThread(requestToEnqueue, true); return requestToEnqueue; }