Event detect when shutdown or restart windows 8 - xaml

I'm working on windows 8 metro style app. I want to show a save confirmation message whenever unexpected events occur such as shutdown or restart and prevent windows to do that event. However, I didn't find any handler event that fitting my need. How can I do that?

In general, a Windows app can prevent shutdown (sometimes) by responding with FALSE to a WM_QUERYENDSESSION message. However, there is no way to get a WindowProc message from a Metro style app. The best you can do in a Metro style app is handle the Suspending event properly in your app (this will not prevent a shutdown of course).

Related

What happens when the user hits the home button?

I have an app which can currently communicate with an server.
Imagine the following case:
User hits some buttons which triggers an server request.
The request is send to the server and is processed.
The user hits the home button (and maybe removes the app from the
memory by hitting the home button two times).
The script is done processing and returns it result.
Question: Will the device from the user gets this response (I am pretty sure it will not when removing from memory, but what when just closing the app)?
There are 5 active states in iOS:
Not running: The app has not been launched or was running but was
terminated by the system.
Inactive: The app is running in the foreground, but not receiving
events. An iOS app can be placed into an inactive state, for
example, when a call or SMS message is received.
Active: The app is running in the foreground, and receiving
events.
Background: The app is running in the background, and executing
code.
Suspended: The app is in the background, but no code is being
executed.
On your third scenario where the user hits the home button, the app will be sent into the Background state, #4, and can still receive data and allow your script to run. If the user kills the app, (state #1) your script will not complete running.
So, to answer your question, yes your app will continue executing code if the user places it in the Background state, but not if they close the app because that will put your app in the Not Running state.
Application is suspended (on the background, not running) - In this case the execution of you requests get paused. When your app gets to the foreground, usually the requests end with a timeout.
Application is terminated - in this case the context of your application is lost and after restarting there are no running requests.
That's the 2 cases you should be concerned about. For me it a good solution to cancel all running requests when the application is entering background because it is easier to restart everything when the app gets to foreground again.
Also, you can setup background mode and that enables the app to perform some code when on the background but that's a more advanced topic.

App crashes when switching applications

When you switch applications or by pressing the Windows button application terminates. But on the first page of this application does not occur. In debug mode, this also happens. The application consumes 28 megabytes of memory. So the system should not terminate it.
Using Prism for windows phone and Unity 3.5 prerelease.
The crash occurs cause GetNavigationState doesn't support serialization of a parameter type which was passed to Frame.Navigate.

System events with vb.net service

I try to create windows service to write events win windows sessionswitch event, but when I make it in windows application it work fine but doesn't work with service.
After search I know the system events need message loop enabled so how I can enable it in vb.net windows service
In order to receive Windows Messages, your program must have a window. As noted on the SessionSwitch MSDN page:
In a Windows service, unless a hidden form is used or the message pump
has been started manually, this event will not be raised.
A link is included which gives an example showing how to receive these events with a hidden window. Message Only Windows are another, similar option for receiving window events and messages.

How to make windows operating system to listen to a user defined event?

I have built a windows metro app in csharp and need to find a way to launch this app when the user for example touches with his finger for 5 seconds anywhere in the start menu.
I have been googling for 2 days but haven't found sth.
Does anybody have any idea?
It's not supported. Windows Store apps can't listen to UI events anywhere outside of their own UI.

How to Turn Off Automatic Termination of Suspended Apps

I'm trying to debug my Windows Store App when it gets suspended (trying to prevent my server app from kicking my WSA client when it gets suspended and stops responding to keep-alive messages). But Windows keeps terminating my app almost immediately after it suspends it. Is there a way to prevent Windows from terminating suspended apps? I've searched the interwebs and the group policy editor for such a setting, but the best I can find is a setting to prevent it from auto-terminating apps on shutdown, which doesn't help me. And of course running in the debugger and pressing the Suspend button doesn't help either, since the app doesn't actually get suspended. I guess I could hack in some debug code to make it pretend to be suspended, but I'd prefer not to.
The command line tool PLMDebug, which is part of the Debugging Tools for Windows package, can be used to exempt an app from the Process Lifetime Management (PLM) policies. When put into debug mode, an app will not be subject to termination and will not be automatically suspended.
Usage:
plmdebug /enableDebug <PackageFullName> [OptionalDebuggerCommandLine]
Once you've exempted it from PLM automatic suspension and termination, you can use /suspend to force a manual suspension.