whoah
whoah

Reputation: 4443

System.OutOfMemoryException in thread

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;
    }

Upvotes: 1

Views: 810

Answers (1)

Orifjon
Orifjon

Reputation: 1097

You have line with for (int i = 0; i < 1; i--)

this is infinite loop.

Upvotes: 4

Related Questions