Metro App can no longer be programmatically killed? - c#

I'm new to Win 8 Metro application development, and discovered that lots of things seem to be changed from the classic WPF.
What troubles me the most is that there's no way to close the app. This is extremely annoying when it comes to debugging the app. Therefore I'm looking at ways to add a "close" button in my app.
However, the old WPF way of:
Application.Current.Shutdown()
no longer exists. And I couldn't find the Process class in System.Diagnostics any more.
Does anyone know how to do this?

You're looking for App.Current.Exit()

The WinRT reference documentation for the developer preview states that:
CoreApplication.Exit | exit method
Shuts down the app.
Source: http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.core.coreapplication.exit.aspx

This is what I found to close the app.
App.Current.Exit();

As far as I know you can't close a Metro app (by design) (using the Task-Manager is the only option that works) and as far as I know there is no way to exit a Metro app programatically (by design too).
You could try to throw an unhandled exception (I wouldn't recommend that).

Try this.. It worked
App.Current.Terminate();

I used crash code to exit Windows 8 Metro APP.
char *p = nullptr;
*p = 1;

Related

Disable ALT+F4 for C# Console Application?

im using c# .net 2.0 Console Application.
How can i prevent my console application from ALT+F4 shortcut?
is there any way to do that?
everywhere there is winform solution.
I need console app solution.
please help me
#Jeroen Mostert:
i found a final working solution from prevent exiting console app by the user.
Everybody says its not possible. But yes it possible with simple tweak.
Here we go
using C#
RegistryKey objRegistryKey = Registry.CurrentUser.CreateSubKey(#"Console");
objRegistryKey.SetValue("AllowAltF4Close", "0" , RegistryValueKind.DWord);
I cant post my full code here due to copyright
but this code works within my application. I tried to make a sample but that not works. But within my full application this works and Nobody can close by pressing ALT+F4.
this is a real solution for all. I don't know which part is required within my all code to make sample.
but this works.
you can just change value 0 to 1 to enable ALT+F4
CMD will not closing if you use this code. try code and launch another cmd.
i dont need to launch another CMD. within my code that works for itself.

Go back to start (windows phone 8) [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Windows Phone 7 close application
How do I programmatically close a WP7 application?
You can always call an exit by doing this at your landing page use this code on click of your application back button:
if (NavigationService.CanGoBack)
{
while (NavigationService.RemoveBackEntry() != null)
{
NavigationService.RemoveBackEntry();
}
}
This will remove back entries from the stack, and you will press a back button it will close the application without any exception.
Acknowledging known solutions to provide "Exit" buttons, currently I do not see a compelling reason to implement an "exit" from a WP7 application.
The platform is fully capable of managing closure of apps. The more apps don't provide an exit, the quicker users will become accustomed to not thinking about app house keeping, and let the platform manage it.
The user will just navigate their device using start, back, etc.
If the user wants out of the current app to go do something else quickly - easy - they just hit start.
.Exit(), whilst available for xna, really isn't required anymore either. There was a cert requirement during CTP that games had to provide an exit button. This is now gone.
Non game apps never had the need to implement this.
The more this topic's discussed (and it really has been given a good run around the block), the more the indicators to me suggest there is no need to code an exit.
It should also be mentioned the app cert reqts are specific that apps should not have unhandled exceptions.
There isn't really a good way to do it. There is a nice explanation/overview of your options here.
For short, if this is a Silverlight app (not XNA), it is not supported. You can simply throw an unhandled exception, and the app will quit. I wouldn't recommend that, it seems like a hack and a rather crude way of doing it.
Here is a way to make it look nicer, but at the end of the day it still throws an exception. I don't know if the application certification process looks at whether you are throwing unhandled exceptions, but I guess it could be an issue.
Simplest thing to do is simulate back from your root/home page. I'm guessing this is exactly what apps (those which have quit button) like Fruit Ninja do.
if ( NavigationService.CanGoBack )
{
NavigationService.GoBack();
}
Btw, above snippet works for a silverlight app.
Another way to exit the application is calling the exit function of the Game class of Microsoft Xna framework.
For example:
Microsoft.Xna.Framework.Game game = new Microsoft.Xna.Framework.Game();
game.Exit();
private void exitBUtton_ONclick(object sender, RoutedEventArgs e)
{
throw new Exception("ExitAppException");
}

programmatically close win8 app

I've begun tinkering with making windows 8 apps And I want to make an exit button.
The problem is that Environment.Exit() and this.Close() that I'd use in winforms isn't in scope here.
anyone know how to close the app Programmatically?
Application.Current.Exit();
But closing a Metro app is not recommended. It is usually suspended.
Application.Exit
But be careful. You can fail certification by having code which forcefully closes the App. Make sure to read up on Certification Guidance if you plan to release to the store:
Your app must neither programmatically close nor offer UI affordances to close it. Windows 8 Process Lifetime Management closes Windows Store apps automatically.
Application.Current.Exit();
This was not allowed, but requirement 3.6, which used to not allow this, seems to be removed :
http://msdn.microsoft.com/en-us/library/windows/apps/hh694083.aspx#acr_changelog

open a .exe as a window in an mdi form?

I wanted to create a program that would allow me to open instances of a already exsiting program (i just have the exe) as windows inside (i belive its called mdi)
Is that something i could do? can anyone point me to an example?
Thanks
Maybe this is the answer you are looking for here. It can be done...look in the sample on that link given.
Hope this helps,
Best regards,
Tom.
When Windows starts a program its parent is the Desktop Window.
If you could somehow manipulate that, it may work.
However, I doubt it is possible, as why would I want to allow you to run my application in your window? Especially MDI? Besides that - running in a child window isn't quite the same as running in the "main" window.
Having said that there is an application out there (can't think of it's name OH) that does place individual applications in tabs. Pretty nifty if you're not on Windows 7. The folks over at the Business of Software forum might be able to help you find it.
Well, after starting the app and storing its PID, you could start monitor the windows that get created, either thru a CBTHook or by just using a timer and the GetWindows to find when a top level window gets created by the PID in question.
Then you can use SetParent to make that window a child to your MDIChild (I doubt you can make it your MDIChild directly).
That should get you going. What you'll run into after that I really don't know. I guess you must correlate any movement of either your app or the external app so that thir windows appears to be stuck together...
Maybo you could strip away the caption from the external app (Get/SetWindowsLong). That could make it look better...

Closing a Windows Mobile Console Application

What is the best and cleanest way to close a console application on windows mobile?
The application by default is invisible and you cannot see it in the running programs, which is great for running a background process, but sometimes the user might need to close it..
Exit Main. Seriously. If you need someone to be able to exit is manually, there needs to be some mechanism like a shell icon and menu or a program in the Programs folder of something. How else would the user even know it's running? Any one of those visual cues would then set a named system event, and inside your Console app you'd have something listening for the same event (likely a worker). When it gets set, you take the actions required to shut down.
How would a user be able to close it if the application is not visible in the UI?
That's a great question. I once spent a long time trying to figure this out. Of course, we are assuming you can not (easily) return from Main. The correct answer on the desktop is System.Environment.Exit; But that method is conveniently not supported on CF.
An apparent second option is Application.Exit. That is on CF, but only applies to WinForms, and is in fact not guaranteed to exit your application.
So, throw an unhandled exception. ;)
EDIT: To kill it programatically from another app, you can look at Process.GetProcessById, and Process.Kill. Both of these are available on CF. You will have to somehow let the "killer" app figure out the "victim"'s ID. More convenient methods like Process.GetProcessesByName are not available on CF.
This technique isn't that elegant, though, and there may be permissions issues.
You could also consider some kind of IPC (inter-process communication), perhaps one overviewed in this previous Windows Mobile answer.
I decided to to read a boolean (keep alive) in the config file and have another application set it to false when I want to exit.
Its not that responsive but at least I can exit cleanly..

Categories