Calling TryClose from ContextMenu on TaskbarIcon leaves process open... somtimes.

Topics: Actions & Coroutines
Apr 22, 2013 at 10:29 PM
I am seeing the following inconsistant behavior: Calling TryClose from a ContextMenu in a TaskbarIcon control (via Message.Attach) closes the window but does not always exit the process. I have two machines I'm testing on, my development VM (win7 with vs2010) and a test machin with win7 and .NET client profile 4. On my development machine it closes as expected, but on the other machine the process just continues to run in the background.

In the project I added a TaskbarIcon from:

I just needed a simple context menu, so I created it in the ShellView:
            <MenuItem Header="Exit" cal:Message.Attach="Exit"/>

CM connects the MenuItem to a function in ShellViewModel :
public void Exit()

To test, I created a button in a sub-view, and also connected it with the same Message.Attach. Clicking on the button correctly closes the application (window and process), but clicking on 'Exit' in the context menu leaves the process running (but only on the test Machine).

I'm not really sure why there would be a difference, I have tried setting ShutdownMode explicitly and calling Application.Current.Shutdown() after TryClose, but they didn't change the behavior.

I have created a simple example project that shows the problem (on my test machine) at:

Any ideas what it's doing?
Apr 22, 2013 at 11:31 PM
Is your shell view the TaskbarIcon itself? If not, what are you attaching it to? Are you disposing the TaskbarIcon on exit?
I am currently using the same control, and I have no issues on exit (got other issues tho, like TaskbarIcon events not being catched by an EventTrigger).
The TaskbarIcon, in my case, is a full-fledged view, using a pseudo-conductor (the bootstrapper) to manage its lifecycle (the taskbar icon is added as an Application resource on startup, and properly disposed on exit).
Apr 22, 2013 at 11:54 PM
No I have a standard View/ViewModel for a main window, and then a sub-View/ViewModel inside the Shell. The Taskbar is just placed inside the ShellView. According to the TaskbarIcon's project page, it should dispose automatically when the window closes, and it does close properly when not being invoked from the TaskbarIcon's ContextMenu.


I was just testing explicitly calling Dispose() on the taskbar object, it didn't work. I did find something else odd. I changed the ShellView's codebhind to:
public partial class ShellView : Window
    public ShellView()

    protected override void OnClosing( System.ComponentModel.CancelEventArgs e )
        MessageBox.Show( "disposing" );
        base.OnClosing( e );
If I comment out the MessageBox call, the process stays open in the background. If i uncomment it, the window and process both close after I hit Ok. Could there be some timing issue?