Пример #1
0
        public IAsyncResult BeginGetRequest(AsyncCallback callback, object stateObject)
        {
#if DEBUG
            if (HttpTraceHelper.Api.TraceVerbose)
            {
                HttpTraceHelper.WriteLine("HttpWebListener#" + HttpTraceHelper.HashString(this) + "::BeginGetRequest()");
            }
#endif
            var asyncResult = new HttpListenerAsyncResult(callback, stateObject, this)
            {
                Request = GetNextRequest()
            };

            //
            // check to see if there are requests in the queue
            //

            if (asyncResult.Request == null)
            {
                //
                // if not go async
                //
                ThreadPool.RegisterWaitForSingleObject(
                    _requestReady,
                    HttpListenerAsyncResult.StaticCallback,
                    asyncResult,
                    -1,
                    true);
            }
            else
            {
                //
                // otherwise complete sync
                //
                asyncResult.Complete(true);
            }

            return(asyncResult);
        }
Пример #2
0
        public IAsyncResult BeginGetRequest(AsyncCallback callback, object stateObject)
        {
            #if DEBUG
            if (HttpTraceHelper.Api.TraceVerbose)
            {
                HttpTraceHelper.WriteLine("HttpWebListener#" + HttpTraceHelper.HashString(this) + "::BeginGetRequest()");
            }
            #endif
            var asyncResult = new HttpListenerAsyncResult(callback, stateObject, this) {Request = GetNextRequest()};

            //
            // check to see if there are requests in the queue
            //

            if (asyncResult.Request == null)
            {
                //
                // if not go async
                //
                ThreadPool.RegisterWaitForSingleObject(
                    _requestReady,
                    HttpListenerAsyncResult.StaticCallback,
                    asyncResult,
                    -1,
                    true);
            }
            else
            {
                //
                // otherwise complete sync
                //
                asyncResult.Complete(true);
            }

            return asyncResult;
        }