这是我的情况。我正在构建一个小型 Windows 窗体,它将在启动时启动并在不使用时在系统托盘中最小化运行。用户将通过系统托盘中的通知图标打开表单,提交表单后,应用程序将最小化回系统托盘。
这一切都很好。然而,我注意到了一些奇怪的事情。当程序首次启动时,任务管理器中的 Mem Usage 显示 ~14000 K。如果我从系统托盘打开表单,它会上升到 ~16000 K。如果我然后将表单最小化回系统托盘,使用率降至 < 1000 K,这很好。我尝试启动应用程序并等待查看使用情况是否随时间下降,但没有看到任何变化。
我担心这一点的原因是因为应用程序将在 Citrix 环境中运行,所以我想在应用程序不使用时降低每个实例的内存使用量,但我不想让用户每天早上登录时打开应用程序并最小化它。
如果有人有任何建议或提示,我将不胜感激。我将包括下面的主要代码块。
public Form1()
{
InitializeComponent();
WindowState = FormWindowState.Minimized;
notifyIcon1.DoubleClick += new EventHandler(notifyIcon1_DoubleClick);
Rectangle r = Screen.PrimaryScreen.WorkingArea;
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height);
currentWorkstation = Environment.GetEnvironmentVariable("clientname");
if (currentWorkstation == null)
currentWorkstation = Environment.MachineName;
GC.KeepAlive(notifyIcon1);
GC.KeepAlive(currentWorkstation);
}
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
Hide();
}
谢谢您的帮助。