How to close Application
-
Saturday, September 17, 2011 7:26 PM
How can I close Metro style application written in C#/XAML? By design we shouldn't close or Can I implement close functionality as below ? Would like to know better apporach.
Application.Current.Exit().
Thanks,
Ajosh
Ajosh Jose
All Replies
-
Sunday, September 18, 2011 12:54 AM
@Ajsoh - by design you shouldn't close your app. This is one of the concepts of Metro apps. The user switches to a different task and the Process Lifetime Management aspects kick in, first suspending your application and then later, if needed, terminating it.
As an app author you should handle Suspending, Resuming correctly to save state and give the user a seemless experience. But the "closing" of apps is not recommended. See the SDK samples for application lifetime for some examples.
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer- Proposed As Answer by Tim Heuer [MSFT]Microsoft Employee Sunday, September 18, 2011 12:54 AM
- Marked As Answer by Jose Atlanta Sunday, September 18, 2011 3:11 AM
-
Monday, September 19, 2011 11:54 PM
Tim,
Where should we direct our extraordinary dissatisfaction with this approach? It is a disaster from both a resource management and task management perspective, and I would like to make sure my voice is heard as loudly and clearly as possible in hopes that it can be changed before release.
Moderator | MCTS .NET 2.0 Web Applications | My Blog: http://www.commongenius.com -
Tuesday, September 20, 2011 12:18 AM
David,
I don't think any amount of expressing dissatisfaction over that would help at this point. This suspension/resuming of apps is a fundamental design feature of Metro (quite similar to WP7 and tombstoning). They've put considerable effort into making sure the app's suspended and won't hog all the CPU/RAM.
I don't like it much either but I guess I'll soon (some day) get used to it.
http://blog.voidnish.com -
Tuesday, September 20, 2011 12:32 AM
The design doesn't have to be fundamentally changed. There is nothing necessarily wrong with it, IF users have the capability of closing apps voluntarily. Without that, apps that the user is not going to use again will hang around in memory. Yes, the system will eventually close them when it needs memory, but the act of shutting them down when the system is already low on memory will be a drain on performance, which would be unnecessary if the user could close the app as soon as they know they are done with it. And of course there is the task management issue that has already been widely discussed in other posts.
Moderator | MCTS .NET 2.0 Web Applications | My Blog: http://www.commongenius.com -
Tuesday, September 20, 2011 3:32 AM
What's odd is that I don't think a clear response from Microsoft has been forthcoming. We're told that closing apps isn't necessary but that doesn't answer the question of why we can't do it anyway.
The user could open the App Bar and click a close button to close the app. Is there some technical reason this can't be done or is it purely aesthetic?
-
Tuesday, September 20, 2011 1:51 PMPLEASE allow users to close apps! It's so annoying flipping through apps trying to find the one you want whenever there is a bunch of open apps that I know longer care about. I've been using Task Manager to kill them off... obviously not the best thing to do.
-
Tuesday, September 20, 2011 2:49 PM
PLEASE allow users to close apps! It's so annoying flipping through apps trying to find the one you want whenever there is a bunch of open apps that I know longer care about. I've been using Task Manager to kill them off... obviously not the best thing to do.
Well it's up to the apps really. If you put a close button and do something like this:Window::Current->Close();
The app will close. It's just not recommended that you do that.
http://blog.voidnish.com- Proposed As Answer by Amare1982 Monday, April 23, 2012 4:22 AM
-
Tuesday, September 20, 2011 8:46 PM
Yes - it does close and leaves you with a green screen. :)
Now, how to get to the Start screen?
David -
Tuesday, September 20, 2011 8:47 PM
Yes - it does close and leaves you with a green screen. :)
Now, how to get to the Start screen?
David
Weird, that's not what I got. I tried this from a C++ WinRT app - not that I think that'd make a difference. I click a button, my code above fires, the window closes, the process exits and I am back on the Metro interface with all the tiles and icons.
http://blog.voidnish.com- Proposed As Answer by Amare1982 Monday, April 23, 2012 4:22 AM
-
Tuesday, September 20, 2011 9:38 PM
Interesting. I have a C# app and hook a button to Window.Current.Close(). When I press it the app closes (as checked in task manager) but I am left with a green screen.
Thought it might be because I was running from VS but I just tried using the app from the start screen with the same result...the green screen.
Hmmm...
David -
Tuesday, September 20, 2011 11:34 PM
@BristleCone43 - yes, the green screen is expected in the preview. The team heard a lot of feedback at BUILD about app closing experiences and are currently soaking it all in. I've forwarded this thread to the UX research team for this feature.
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer- Marked As Answer by Rob CaplanMicrosoft Employee, Moderator Wednesday, September 21, 2011 6:34 PM
-
Wednesday, September 21, 2011 1:54 AM
Interesting. I have a C# app and hook a button to Window.Current.Close(). When I press it the app closes (as checked in task manager) but I am left with a green screen.
Thought it might be because I was running from VS but I just tried using the app from the start screen with the same result...the green screen.
Hmmm...
David
Hey David,I tested again, you are right, the window closes but it takes you to the blank green screen. If you click anywhere on the screen, all the tiles come back.
Not sure how I got different behavior earlier, maybe I accidentally clicked on the screen or something.
http://blog.voidnish.com- Proposed As Answer by Amare1982 Monday, April 23, 2012 4:22 AM
-
Wednesday, September 21, 2011 5:45 AM
Yes...I just tried that and have the same behavior. Actually easier than pressing the 'windows' key.
Thanks...
BTW...I like the new capability of having spell checker everywhere. I just misspelled behavior and had it highlighted. Right clicked it and was shown the correct spelling. Nice!
David -
Wednesday, September 21, 2011 5:45 AMThanks Tim
David- Edited by BristleCone43 Wednesday, September 21, 2011 5:45 AM
-
Monday, September 26, 2011 2:13 AM
Hey Tim, one of the issues I ran into was that I was using an app that had sound playing. When I selected a new app, the previous app that was no longer in view, continued to "play". My only recourse was to use task manager to kill the app. There are certain scenarios when you want to do something once, and then close it. For example, changing a setting in the control panel - once I have made my update, it is really annoying for the control panel app to continue in my "deck" of apps as I flip between them.
Just my 2 cents.
Thanks,
Bob -
Monday, September 26, 2011 2:17 AM
Bob, when you say selected a new app...did you mean the Start screen? if an app had media playing and you go to the Start screen, it will still be playing because the Start screen is a launcher, not an "app" -- however, if you then initiated another app, it should have closed the audio port for the other one.
An example of this could be seen using this repro:
- Start Zero Gravity game (you should hear background music when starting in a level)
- Click Start menu
- You should still hear the audio from Zero Gravity
- Select Sudoku
- You should no longer hear the ZeroG audio
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer -
Sunday, October 02, 2011 3:17 PM
I'm personally concerned about Metro causing a user to run up their mobile bill. Since Metro is supposed to be able to be used for tablets that could be on mobile connections like Verizon wireless, this could get expensive if the user wants to stop having the app download data but the app continually updates or doing what it was doing in the background.
So, I like the concept but don't like how it's completely forced on the user. I think there will be unforseen consequences and angry users. I can guarantee it will be a fail. Instead, just make apps not close by default and the user has to explicitly close the app when they leave it. That's how launchers usually work anyway.
- Edited by netdragon2012 Sunday, October 02, 2011 3:18 PM
-
Sunday, October 02, 2011 3:59 PM
@netdragon2012 - that's a valid concern actually. There are APIs in Win8 for you to build in monitoring of bandwidth and control some throttling. I can't recall if there is an SDK sample on this area or not, but I'd search there for it. However keep in mind that unless the app is in the foreground there is no code running. So unless an app is doing *specific* background activity (of the only allowed background activity like music playback, etc.) then when your app is suspended it isn't running until the user brings it back to foreground again.
Take a look at Ben's session about this topic: http://channel9.msdn.com/Events/BUILD/BUILD2011/APP-409T
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer -
Wednesday, October 05, 2011 2:50 PMModerator
It seems like there is going to be relief on this issue. Please see http://blogs.msdn.com/b/b8/archive/2011/10/03/evolving-the-start-menu.aspx:
"With regard to the main user experience, particularly Start, we’re noticing some themes in your comments. Will there be a way to close Metro style apps without going to Task Manager? (Yes there will be, but we also want to talk about why you probably won't need to use it.) "
Matt Small - Microsoft Escalation Engineer - Forum Moderator -
Saturday, August 11, 2012 8:46 PM
Windows 8 Release Preview.
I tried to use the Window.Current.Close()
It indeed close the app but in fact it doesn't. Let me explain :)When the app closes, I'm back in Start Screen however, when I look at the running apps, the app is still running I just have to select it and I'm back in it.
So Close() doesn't really close it. It looks like it's just hiding it. -
Saturday, August 11, 2012 9:53 PMThat's the expected behaviour. Your app shouldn't attempt to close itself or provide any mechanism for "closing", instead rely on the system to manage the lifecycle of your app if the user switches away. If they really want to close it, they can use the system provided mechanisms for doing so.
-
Sunday, August 12, 2012 9:30 AM
Ok,
Would you mind telling me why the Close exists and why we should use it ?
-
Sunday, August 12, 2012 11:00 PM
You said you used Window.Current.Close (which is basically Window.Close). This is different than Application.Exit() (which you shouldn't really use either). An app can have multiple Windows, so using the Close method on that makes sense in those situations. In 99% of apps there likely aren't going to be multiple windows though. In an app that only has a single window, the Close method essentially puts it in a situation where there is no other content to display, thus suspends the app.
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)- Proposed As Answer by GearWorld Monday, August 13, 2012 9:53 AM
-
Monday, August 13, 2012 9:55 AM
Thank you
-
Friday, February 01, 2013 11:01 PM
I know I'm bringing up a very old thread here, but bear with me.
My application connects to SkyDrive. If the user does not give permission to connect I ask the user if they would like to connect with permission. Surely, if they say no, there is no point in suspending (requesting permission is the first thing the application does).
In this case, would application.current.exit be the best option?
Thanks
DavidDavid Overton - here as myself (Author) of Windows Intune 2.0:Quickstart Administrators Guide http://davidoverton.com/windowsintune
-
Saturday, February 02, 2013 6:00 AMModerator
Instead of closing the app leave it on a page saying that it cannot continue and let the user switch away, close it themselves, or change their mind and give permission to connect.
Certification requirement 3.6 states:
Your app must neither programmatically close nor offer UI affordances to close it. Windows 8 Process Lifetime Management closes Windows Store apps automatically.
--Rob


