I want download string with timeout=10sec. This code forever goto theEnd, and I can't understand why.
wc.DownloadStringCompleted += (ender,args)=>
{
res = args.Result;
var cook = Regex.Matches(wc.ResponseHeaders.ToString(), "Set\\-Cookie:\\s*([\\w\\-_\\.]+\\s*=\\s*[^;]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline);
foreach (Match val in cook)
cookies += val.Groups[1].Value.Trim() + "; ";
};
wc.DownloadStringAsync(new System.Uri(url));
int msec = 0;
while (String.IsNullOrEmpty(res))
{
Thread.Sleep(1);
++msec;
if (msec >= 10000)
{
lastError = "TimeOut";
goto theEnd;
}
}
return res;