C# Form内存回收
2016-05-11 11:50
363 查看
namespace WebBrowserMemoryTest { public partial class Form1 : Form { private int _Pages; public Form1() { InitializeComponent(); webBrowser1.Navigate("http://www.google.com"); } private void startButton_Click(object sender, EventArgs e) { _Pages = 0; timer1.Start(); } private void stopButton_Click(object sender, EventArgs e) { timer1.Stop(); } private void timer1_Tick(object sender, EventArgs e) { HtmlElement next = webBrowser1.Document.GetElementById("pnnext"); if (_Pages <= 90) { if (null != next) { string href = next.GetAttribute("href"); webBrowser1.Navigate(href); _Pages++; } else { timer1.Stop(); MessageBox.Show("Next button not found"); } } else { timer1.Stop(); MessageBox.Show("Done"); } } private void goButton_Click(object sender, EventArgs e) { webBrowser1.Navigate(textBox1.Text); } private void freeMemButton_Click(object sender, EventArgs e) { MemoryManagement.FlushMemory(); } } public class MemoryManagement { [DllImport("kernel32.dll")] public static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max); public static void FlushMemory() { GC.Collect(); GC.WaitForPendingFinalizers(); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); } } } }
相关文章推荐
- 【C#设计模式-责任链模式】
- C# 动态显示曲线
- c#中开发ActiveX的学习笔记【转】
- C#中Monitor和Lock以及区别
- C# winform Listbox添加和删除items
- 分享C#中几个可用的类
- C#程序输出信息到调试窗口的几种方式
- C#中Timer使用及解决重入问题
- C#运算符之与,或,异或及移位运算
- C#面向对象设计的七大原则
- C#开发中怎么提升excel导出速度
- C#实现简单的汽车租赁系统
- C# 委托 delegate
- c#中取整,向上取,向下取
- C# 判断文件夹存在与否并创建文件夹
- C#中的invoke和begininvoke
- C# 获取windows特殊路径
- 漫谈C#编程语言在游戏领域的应用
- C#动态编译、执行代码
- C#集合接口与集合类