开发者

polling and timeout

开发者 https://www.devze.com 2023-01-24 07:37 出处:网络
I am polling a web service for a specific return value. (Using sync call since the web service returns right away). How to implement a t开发者_开发技巧imeout for this kind of polling, say 10 minutes a

I am polling a web service for a specific return value. (Using sync call since the web service returns right away). How to implement a t开发者_开发技巧imeout for this kind of polling, say 10 minutes and I will stop polling?


The simplest example I can think of is something like...

var service = new MyService();
var result = false;
var start = DateTime.Now;

while (!result && DateTime.Now < start.AddMinutes(10)) {
    result = service.Execute();
}
if (result){
    // Call successful
} else {
    // Routine timeout
}

But having more information would help. You may then want to put a similar routine in another thread to prevent your application from locking up.


Without anymore detail I can only offer you the following

HttpWebRequest.Timeout Property

WebRequest.Timeout Property

0

精彩评论

暂无评论...
验证码 换一张
取 消