I have a windows form application in which the Form1 object's initial WindowState == Minimized. This works as desired in the sense that the application does indeed start minimized etc. However, the application shows up in the applications tab of the taskmgr which is undesirable.
I've only personally been able to reproduce this on Vista. I could not reproduce this on WinXP or Windows 2003). My customer has said this does happen on WinXP sp3. So, it may be related to the .NET framework service packs installed and not necessarily an OS issue -- or they passed wrong information to me about winxp.
Regardless of what the particular combination is... I need a fix.
I have tried:
- In my Form constructor, putting
this.WindowState==Minimized
and this.Hide(). This didn't help. (Would theForm_Load
event handler do anything different? I've had similar issues like this in the past and Form_Load never seemed to do anything different then the form constructor so I haven't tried)
Workarounds:
- I have a
MinimizeApplication()
method which doesthis.WindowState=Minimized; this.Hide();
, if after the application loads I click a context menu shortcut on the applications SystemTray (akaNotifyIcon
) which callsMinimizeApplication()
it disappears from the taskmanager. - In a timer's DoWork, I was able to call
MinimizeApplication()
which worked. But, this seemed like a real hack.
Please Note: There is a difference between the application tab and the process tab on taskmgr. I'm not trying to do something sketchy like hide all evidence that my application is running.
Edit 1 This is the how I implemented the workaround. Perhaps it'll shed some light on the problem.
Timer mMinimizeTimer = null;
public Form1(string[] args)
{
this.WindowState = FormWindowState.Minimized;
this.Hide();
mMinimizeTimer = new Timer();
mMinimizeTimer.Tick += new EventHandler(mMinimizeTimer_Tick);
mMinimizeTimer.Interval = 500;
mMinimizeTimer.Enabled = true;
}
void mMinimizeTimer_Tick(object sender, EventArgs e)
{
// Forces minimize after application starts. This is a workaround to prevent
// application from showing up in the taskmanager -> Applications tab on Vista.
this.Hide();
mMinimizeTimer.Enabled = false;
}