I've been going at this all day. I am creating web requests using
public async static Task<string> FetchString(string Url)
{
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(Url);
Request.Proxy = null;
WebResponse Response = await Request.GetResponseAsync();
Stream DataStream = Response.GetResponseStream();
if (DataStream == null) return String.Empty;
StreamReader DataReader = new StreamReader(DataStream);
return await DataReader.ReadToEndAsync();
}
which works great. The problem is, though, is that sometimes it hangs on HTTP 504, gateway timeout. Using Request.Timeout (or any of the three variants) does not time the method out for when my method hangs on 504 (edit: timeout doesn't reply to async methods, great). To combat this, I've tried to create a timer that would kill the thread the request was running on, but had no luck doing that, though it felt like a working concept.
How would I be able to asynchronously get the contents of a URL in string form, while still being abe to time the request out after say five seconds?