I have a problem. This part of code returns after ~1min System.OutOfMemoryException error. But I can't find what exacly causes this error. I would be glad if somebody will tell me what is the reason of this issue, and how to resolve it.
Part of my thread:
public void Run(object client)
{
TextBox tbServerResult = (client as Client).Controls.Find("tbServerResult", true).SingleOrDefault() as TextBox;
Client tt = new Client();
for (int i = 0; i < 1; i--)
{
Thread.Sleep(10000);
string result = tt.SendGet("xyz" + tt.getToken() + "");
tbServerResult.AppendText(result);
}
}
SendGet method:
public string SendGet(string url)
{
string webpageContent = "";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
{
using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
{
webpageContent = reader.ReadToEnd();
}
//tbServerResult.AppendText("\r\n" + "Server code:" + webResponse.StatusCode + " Server status description:" + webResponse.StatusDescription);
webpageContent = "Server code:" + webResponse.StatusCode + " Server status description:" + webResponse.StatusDescription;
}
}
catch (Exception ex)
{
webpageContent = ex.Message;
}
return webpageContent;
}
reader.ReadToEnd()I don't see any likely candidates for an OutOfMemoryException either, but even then that would mean some pretty fast downloading if it runs out after 1 minute...AppendTexton a background thread should fail. So probably the OutOfMemoryException occurs before it actually tries to access the control.