您的位置:首页 > 编程语言 > C#

关于C#的WebBrowser内存占用太大的解决办法

2016-07-15 14:58 459 查看
这段时间在用WebBrowser,发现只要不释放,这家伙占的内存,就会与越来越大。我都到过1G多,好吓人。于是百度查找解决方法最终在下面的网址中到到了,在此先表示感谢。

网站:http://bbs.csdn.net/topics/390164193

解决方法如下:

-- in class definition

[DllImport("KERNEL32.DLL", EntryPoint = "SetProcessWorkingSetSize", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool SetProcessWorkingSetSize(IntPtr pProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);

[DllImport("KERNEL32.DLL", EntryPoint = "GetCurrentProcess", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
internal static extern IntPtr GetCurrentProcess();

-- code to call when you want to reduce the memory

IntPtr pHandle = GetCurrentProcess();
SetProcessWorkingSetSize(pHandle, -1, -1);


本人在WIN7,VS2013下测试可行
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C# WebBrowser