/// <summary>
        ///    <para>Processes async queued requests that are blocked on needing a free pooled stream
        ///         works as follows:
        ///         1. while there are blocked requests, take one out of the queue
        ///         2. Wait for a free connection, when one becomes avail, then notify the request that its there
        ///         3. repeat 1 until there are no more queued requests
        ///         4. if there are no more requests waiting to for a free stream, then close down this thread
        ///</para>
        /// </summary>
        private void AsyncThread()
        {
            do
            {
                while (m_QueuedRequests.Count > 0)
                {
                    bool continueLoop = true;
                    AsyncConnectionPoolRequest asyncState = null;
                    lock (m_QueuedRequests) {
                        asyncState = (AsyncConnectionPoolRequest)m_QueuedRequests.Dequeue();
                    }

                    WaitHandle [] localWaitHandles = m_WaitHandles;
                    PooledStream  PooledStream     = null;
                    try {
                        while ((PooledStream == null) && continueLoop)
                        {
                            int result = WaitHandle.WaitAny(localWaitHandles, asyncState.CreationTimeout, false);
                            PooledStream =
                                Get(asyncState.OwningObject, result, ref continueLoop, ref localWaitHandles);
                        }

                        PooledStream.Activate(asyncState.OwningObject, asyncState.AsyncCallback);
                    } catch (Exception e) {
                        if (PooledStream != null)
                        {
                            PooledStream.Close();
                            PutConnection(PooledStream, asyncState.OwningObject, asyncState.CreationTimeout);
                        }
                        asyncState.AsyncCallback(asyncState.OwningObject, e);
                    } catch {
                        if (PooledStream != null)
                        {
                            PooledStream.Close();
                            PutConnection(PooledStream, asyncState.OwningObject, asyncState.CreationTimeout);
                        }
                        asyncState.AsyncCallback(asyncState.OwningObject, new Exception(SR.GetString(SR.net_nonClsCompliantException)));
                    }
                }
                Thread.Sleep(500);
                lock (m_QueuedRequests) {
                    if (m_QueuedRequests.Count == 0)
                    {
                        m_AsyncThread = null;
                        break;
                    }
                }
            } while (true);
        }
示例#2
0
        private void AsyncThread()
        {
Label_00B1:
            while (this.m_QueuedRequests.Count > 0)
            {
                bool continueLoop = true;
                AsyncConnectionPoolRequest request = null;
                lock (this.m_QueuedRequests)
                {
                    request = (AsyncConnectionPoolRequest)this.m_QueuedRequests.Dequeue();
                }
                WaitHandle[] waitHandles  = this.m_WaitHandles;
                PooledStream pooledStream = null;
                try
                {
                    while ((pooledStream == null) && continueLoop)
                    {
                        int result = WaitHandle.WaitAny(waitHandles, request.CreationTimeout, false);
                        pooledStream = this.Get(request.OwningObject, result, ref continueLoop, ref waitHandles);
                    }
                    pooledStream.Activate(request.OwningObject, request.AsyncCallback);
                    continue;
                }
                catch (Exception exception)
                {
                    if (pooledStream != null)
                    {
                        this.PutConnection(pooledStream, request.OwningObject, request.CreationTimeout, false);
                    }
                    request.AsyncCallback(request.OwningObject, exception);
                    continue;
                }
            }
            Thread.Sleep(500);
            lock (this.m_QueuedRequests)
            {
                if (this.m_QueuedRequests.Count == 0)
                {
                    this.m_AsyncThread = null;
                }
                else
                {
                    goto Label_00B1;
                }
            }
        }