コード例 #1
0
        private static void complete(HttpListenerAsyncResult asyncResult)
        {
            lock (asyncResult._sync) {
                asyncResult._completed = true;

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

            var callback = asyncResult._callback;

            if (callback == null)
            {
                return;
            }

            ThreadPool.QueueUserWorkItem(
                state => {
                try {
                    callback(asyncResult);
                }
                catch {
                }
            },
                null
                );
        }
コード例 #2
0
        internal HttpListenerAsyncResult BeginGetContext(HttpListenerAsyncResult asyncResult)
        {
            lock (_ctxRegistrySync) {
                if (!_listening)
                {
                    throw new HttpListenerException(995);
                }

                var ctx = getContextFromQueue();
                if (ctx == null)
                {
                    _waitQueue.Add(asyncResult);
                }
                else
                {
                    asyncResult.Complete(ctx, true);
                }

                return(asyncResult);
            }
        }