I have the following code inside my asp.net mvc action method. the code will loop through a list of servers and for each server it will make a call to a third party system using WebClient()
call.
//loop started
try
{
using (WebClient wc = new WebClient()) // call the Third Party API to get the account id
{
string url = currentURL + "resources/" + ResourceID + "/accounts?AUTHTOKEN=" + pmtoken;
var json = await wc.DownloadStringTaskAsync(url);
}
}
catch (Exception)
{
c.ScanResult = "Call to Third Party system Failed ";
scan.Description = scan.Description + "<span style='color:red'>" + c.ScanResult + "</span><br/>";
repository.Save2();
continue;
}
//end of loop
currently i am facing a problem if that when the loop start it will be working well,, and the WebClient()
call will work normally... but after successive WebClient()
requests the method will hang and seems the WebClient()
call will hang for some reasons (maybe a problem in the third party system), and the whole method execution will stop (never ends), so can any one adivce how i can force the WebClient()
to continue execution if it does not receive any response within certain amount of time (for example 5 minutes)? as currently no exception will be raised and the loop will never ends ..
Thanks