线程中的System.OutOfMemoryException

时间:2013-12-23 10:24:58

标签: c# .net

我有问题。这部分代码在〜1min System.OutOfMemoryException错误后返回。但我无法找到什么可能导致这个错误。如果有人告诉我这个问题的原因是什么,以及如何解决它,我会很高兴。

我的部分主题:

    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方法:

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

1 个答案:

答案 0 :(得分:5)

您与for (int i = 0; i < 1; i--)

对齐

这是无限循环。