本文整理汇总了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);
}