polling and timeout
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
精彩评论