private static void complete(HttpListenerAsyncResult asyncResult)
        {
            asyncResult._completed = true;

              var waitHandle = asyncResult._waitHandle;
              if (waitHandle != null)
            waitHandle.Set ();

              var callback = asyncResult._callback;
              if (callback != null)
            ThreadPool.UnsafeQueueUserWorkItem (
              state => {
            try {
              callback (asyncResult);
            }
            catch {
            }
              },
              null);
        }
        internal HttpListenerAsyncResult BeginGetContext(HttpListenerAsyncResult asyncResult)
        {
            CheckDisposed ();
              if (_prefixes.Count == 0)
            throw new InvalidOperationException ("The listener has no URI prefix on which listens.");

              if (!_listening)
            throw new InvalidOperationException ("The listener hasn't been started.");

              // Lock _waitQueue early to avoid race conditions.
              lock (_waitQueueSync) {
            lock (_ctxQueueSync) {
              var ctx = getContextFromQueue ();
              if (ctx != null) {
            asyncResult.Complete (ctx, true);
            return asyncResult;
              }
            }

            _waitQueue.Add (asyncResult);
              }

              return asyncResult;
        }