Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7016721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:49:19+00:00 2026-05-27T22:49:19+00:00

I’m looking for a best practice (if there is even a best) for cleanly

  • 0

I’m looking for a “best practice” (if there is even a best) for cleanly shutting an WPF application down that uses MEF and PRISM4. Ultimately, I’m looking for some sort of “Close Service” would manage all of event/commanding from the Shell to any viewmodel (or other subscribers) that want to verify it’s OK to close the application. Is the event aggregator the cleanest way? Other opinions/options?

Ideally, I’d have a button on my ToolbarView in my ToolbarRegion (1 of 2 regions in my Shell). This button would invoke a command on my ToolbarViewModel (referencing a command on my ToolbarControler) which in turn would do 2 things (I think?)…First, notify all subscribers that it’s closing time and allow any of them to cancel the close and…secondly, if none cancel, somehow notify the shell to close. My app’s shutdown mode is set to “ShutdownMode.OnMainWindowClose” so if the Shell closes, I should be all set.

Can someone help me out with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:49:20+00:00Added an answer on May 27, 2026 at 10:49 pm

    I’m developping a large application using the same stuff: MEF and PrismV4

    I handle shutdown it a bit differently:
    in the Shell, there is a “Tools” Region, shutdown for that is handled right in the Shell, on the close event.
    Then for everything injected in the other region, which is a tabcontrol, I cast the content as IDisposable, and close every tab one by one. (Actually, it’s not a tabcontrol, it’s an avalondock component, but it’s the same thing really).
    Of course, you’ll have to implement IDisposable on every class that has references etc to dispose, but it’s hard to think of a “clean way of shutting down” without meantioning that interface right? =)

    Now, about the EventAggregator: you may very well run into trouble, because there is no coupling: you can fire a weak event through it, but you can’t wait for objects to do their work after that.
    And then, you couldn’t make a mechanism to cancel the shutdown.

    In case you want your various views to be able to cancel the shutdown, i suggest you create an interface with a single method in it:

    public interface IShutdownAware
    {
       bool CanShutdown();
    }
    

    Then right before you call dispose, call CanShutdown(); if they all return true, proceed with disposing, otherwise, cancel the shutdown process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.