当前位置: 首页>>代码示例>>C#>>正文


C# RequestState.WaitOne方法代码示例

本文整理汇总了C#中RequestState.WaitOne方法的典型用法代码示例。如果您正苦于以下问题:C# RequestState.WaitOne方法的具体用法?C# RequestState.WaitOne怎么用?C# RequestState.WaitOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RequestState的用法示例。


在下文中一共展示了RequestState.WaitOne方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MaxTimedOutRequests

        public void MaxTimedOutRequests()
        {
            var queue = new HttpRequestQueue();

            // get queue into running state
            var webRequest = this.CreateWebRequest(string.Empty);
            var requestState = new RequestState();
            queue.Enqueue(webRequest, this.ResponseCallBack, requestState);
            Assert.IsTrue(requestState.WaitOne());
            Assert.AreEqual(HttpRequestQueueResultCode.Success, requestState.Result);
            Assert.AreEqual(HttpRequestQueueState.Running, queue.QueueState);

            // timeout a request
            webRequest = this.CreateWebRequest("Timeout");
            requestState = new RequestState();
            queue.Enqueue(webRequest, this.ResponseCallBack, requestState);
            Assert.IsTrue(requestState.WaitOne(TimeOutMilliseconds * 2));
            Assert.AreEqual(HttpRequestQueueResultCode.RequestTimeout, requestState.Result);

            // queue should be still in running state because no value for 
            // MaxTimedOutRequests are specified
            Assert.AreEqual(HttpRequestQueueState.Running, queue.QueueState);
            Assert.AreEqual(0, queue.TimedOutRequests);

            queue.MaxTimedOutRequests = 2;
            webRequest = this.CreateWebRequest("Timeout");
            requestState = new RequestState();
            queue.Enqueue(webRequest, this.ResponseCallBack, requestState);
            Assert.IsTrue(requestState.WaitOne(TimeOutMilliseconds * 2));
            Assert.AreEqual(HttpRequestQueueResultCode.RequestTimeout, requestState.Result);

            // queue should be still in running state because the specified MaxTimedOutRequests 
            // value is not reached
            Assert.AreEqual(HttpRequestQueueState.Running, queue.QueueState);
            Assert.AreEqual(1, queue.TimedOutRequests);

            webRequest = this.CreateWebRequest(string.Empty);
            requestState = new RequestState();
            queue.Enqueue(webRequest, this.ResponseCallBack, requestState);
            Assert.IsTrue(requestState.WaitOne(TimeOutMilliseconds));
            Assert.AreEqual(HttpRequestQueueResultCode.Success, requestState.Result);

            webRequest = this.CreateWebRequest("Timeout");
            requestState = new RequestState();
            queue.Enqueue(webRequest, this.ResponseCallBack, requestState);
            Assert.IsTrue(requestState.WaitOne(TimeOutMilliseconds * 2));
            Assert.AreEqual(HttpRequestQueueResultCode.RequestTimeout, requestState.Result);

            // queue should be still in running state because the counter for 
            // timed out requests is reset by the successfull request
            Assert.AreEqual(HttpRequestQueueState.Running, queue.QueueState);
            Assert.AreEqual(1, queue.TimedOutRequests);

            webRequest = this.CreateWebRequest("Timeout");
            requestState = new RequestState();
            queue.Enqueue(webRequest, this.ResponseCallBack, requestState);
            Assert.IsTrue(requestState.WaitOne(TimeOutMilliseconds * 2));
            Assert.AreEqual(HttpRequestQueueResultCode.RequestTimeout, requestState.Result);

            // queue should be in offline state because the counter for 
            // timed out requests reached the MaxTimedOutRequests value
            Assert.AreEqual(2, queue.TimedOutRequests);
            Assert.AreEqual(HttpRequestQueueState.Offline, queue.QueueState);
        }
开发者ID:ommziSolution,项目名称:PhotonServer,代码行数:64,代码来源:HttpRequestQueueTests.cs


注:本文中的RequestState.WaitOne方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。