110,536
社区成员
发帖
与我相关
我的任务
分享
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
webBrowser1.Navigate("http://www.qq.com/");
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
webBrowser1.Dispose();
webBrowser1 = null;
}
}
///////////////////////
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
Thread thread = new Thread(new ThreadStart(delegate
{
Form2 f = new Form2();
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Interval = 2000;
timer.Tick += delegate(object o, EventArgs args)
{
timer.Dispose();
f.Close();
};
timer.Start();
f.ShowDialog();
Thread.CurrentThread.Abort();
}));
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
}
-- 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);