WebSocketSharp.Net.HttpListener.EndGetContext C# (CSharp) Method

EndGetContext() public method

Ends an asynchronous operation to get an incoming request information.
This method completes an asynchronous operation started by calling the BeginGetContext method.
/// This object has been closed. /// /// is . /// /// was not obtained by calling the method. /// /// The EndGetContext method was already called for the specified . ///
public EndGetContext ( IAsyncResult asyncResult ) : HttpListenerContext
asyncResult IAsyncResult /// An obtained by calling the method. ///
return HttpListenerContext
        public HttpListenerContext EndGetContext(IAsyncResult asyncResult)
        {
            CheckDisposed ();
            if (asyncResult == null)
                throw new ArgumentNullException ("asyncResult");

            ListenerAsyncResult ares = asyncResult as ListenerAsyncResult;
            if (ares == null)
                throw new ArgumentException ("Wrong IAsyncResult.", "asyncResult");

            if (ares.EndCalled)
                throw new InvalidOperationException ("Cannot reuse this IAsyncResult.");
            ares.EndCalled = true;

            if (!ares.IsCompleted)
                ares.AsyncWaitHandle.WaitOne ();

            lock (((ICollection)wait_queue).SyncRoot) {
                int idx = wait_queue.IndexOf (ares);
                if (idx >= 0)
                    wait_queue.RemoveAt (idx);
            }

            HttpListenerContext context = ares.GetContext ();
            context.ParseAuthentication (SelectAuthenticationScheme (context));
            return context; // This will throw on error.
        }