views:

136

answers:

5

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==Minimizedand this.Hide(). This didn't help. (Would the Form_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 does this.WindowState=Minimized; this.Hide();, if after the application loads I click a context menu shortcut on the applications SystemTray (aka NotifyIcon) which calls MinimizeApplication() 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;
    }
+3  A: 

Try setting ShowInTaskbar = false on the Form.

Adam Robinson
@Adam Robinson I already set this property in the designer. Thanks though.
blak3r
+3  A: 

Have you tried to set Form.ShowInTaskBar = false?

Tor Haugen
@Tor Haugen I already set this property in the designer. Thanks though
blak3r
+1  A: 

I guess in the main method you start the form by calling

Application.Run(new Form1())

try doing like this:

Form1 frm = new Form1();
Application.Run();

this way the form will be instantiated but not shown on at all even in the TaskManager applications tab. (Application.Run will set form given as parameter visiblity to true)

P.S.: Why don't you create a .NET Service instead of a .NET WinForm Application?

najmeddine
@najmeddine I'll give that a try. Gotta track down that vista laptop. I want a WinForm Application b/c the Form pops up if certain data is received from a webservice.
blak3r
That worked! Any side effects that you can think of off hand?
blak3r
From what I understood, when you want to close this app you have to kill it! Depending on what it's doing at that instant, problems can arise: I/O operations, data saving, .. May be you can add a TrayIcon where you can command your App from there: settings, closing, ...
najmeddine
Yeah... also my application failed to maximize properly. Back to the drawing board.
blak3r
well, when you maximized it, did set it Visible first?
najmeddine
+1  A: 

Do you need a form to show?

Instead of starting with a form, you could also startup an application controller, which could do your work

You can take a look at the application.Run() or Application.Run(context) methods to start up your app

Heiko Hatzfeld
@Heiko Hatzfeld Thanks for your suggestion. If i was redesigning my application from scratch, I'd probably go that route for a number of reasons including the one you mentioned. But, for now I'm just trying to fix my Vista/Windows7 issue.
blak3r
A: 

I never did find the answer to this problem I was hoping for. I'm still using the workaround that I have outlined in my question above. The workaround has now been "field tested" by having my customer install it on the problematic PCs and so far so good.

If anyone has a better solution / explanation of what OS's/.NET versions cause this behavior, please post it!

blak3r