I am experiencing the weirdest problem I have seen in a very long time.
I launch 2 threads, where each thread creates a HttpWebRequest. These
threads are started at the same time (well, one millisecond apart). What
happens is that the call to GetResponse() from the first HTTP request
sometimes receives the contents of the second HTTP request. When this
happens, the second HTTP request times out after 30 seconds.
This doesn't happen every time, but it does happen 4 out of 5 times.
This is the code: (simplified to produce a working test case)
public void Launch()
{
Thread thread1 = new Thread(() => { GetData("http://url1"); });
Thread thread2 = new Thread(() => { GetData("http://url2"); });
thread1.Start();
thread2.Start();
}
public static void GetData(string url)
{
try
{
XDocument xDoc;
var webRequest = HttpWebRequest.Create(url);
using (var response = webRequest.GetResponse())
{
using (var stream = response.GetResponseStream())
{
xDoc = XDocument.Load(stream);
Logger.Default.Log(xDoc);
}
}
}
catch(Exception ex)
{
Logger.Default.LogException(ex);
}
}
--
View this message in context:
http://monotouch.2284126.n4.nabble.com/HttpWebRequest-in-thread-returns-result-from-another-thread-tp4657042.html
Sent from the MonoTouch mailing list archive at Nabble.com._______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch