高内存使用c#webbrowser用于触摸屏

时间:2017-02-20 00:37:38

标签: c# winforms input memory-leaks

我正在寻找解决问题超过一周的问题。目前,我正在为触摸屏创建一个浏览器。我创建了自己的键盘(Form2),当浏览器具有输入状态(例如google中的搜索引擎)时,它会打开。一切都很好但是当我开始浏览时,5分钟后内存开始超过300 mb。

这是一个导致内存问题的错误代码 - 如果没有这一切就可以了。

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        foreach (HtmlElement input in webBrowser1.Document.GetElementsByTagName("input"))

        {

            if (input.GetAttribute("type").ToLower() == "text")
            {
                input.GotFocus += AttachKeyboard;
                input.LostFocus += RemoveKeyboard;

            }

        }

     }
public void AttachKeyboard(object sender, EventArgs e)
    {
       Form2.Instance.Show();        
    }
public  void RemoveKeyboard(object sender, EventArgs e)
    {
       Form2.Instance.Hide();
    }

我尝试使用-=取消订阅活动,但没有效果。 在Windows 7,8,10上测试了问题 非常感谢您的帮助。我开始学习C#语言了。

编辑 当我删除这一行时,一切都没问题。

            input.GotFocus += AttachKeyboard;
            input.LostFocus += RemoveKeyboard;

0 个答案:

没有答案
相关问题