UWP Restart when closed by user - c#

I have a uwp app that launches an external application (Notepad). I want to make it so that when the user closes the Notepad app by clicking the red x button in the top-right corner, Notepad restarts itself. Is this even possible and if so, how do I do it?

To restart the application on exit, you can take advantage of the confirmAppClose capability. When you capture the close event, you can launch the app and then finish closing the current instance. Keep in mind this is a restricted capability and will require special approval from Microsoft to submit to the Microsoft Store.

Related

Detect user selected option on Windows preventing restart C#

So i have a program that runs in background and by accident i found that if you prompt restart and get the screen that some app prevents it if you click cancel my app actually dies. Is there a way to make app wait more or to check what user selected on that screen.
What i meant is this:
After this screen when i go cancel my app is dead.

Opening another WinRT app from another running app in FULL mode

I have 2 apps. I am running one in full mode and want to click a button from the first app to launch the second app .
My problem is that my second app is getting launched but both apps are in Snapped mode.
I programatically want to allow the other app to open in fill mode and first app should be in the memory.
Any help ?
Windows Store apps don't have any way to directly launch other apps. I assume you're launching a URI or file and your app is registered as the default handler (users can choose something else).
In your call to Launcher.LaunchUriAsync you can set the DesiredRemainingView in your LauncherOptions to indicate how much of the screen you'd like your app to keep. This is non-binding, but likely to be followed for UseNone. If there's room for UseHald (the default) then UseLess to snap/fill will likely be respected as well.

How to suspend/minimize/exit Windows Phone application programmatically?

My Windows Phone 8 application checks network connectivity in OnNavigatedTo method. If the application finds out there's no network available, what should my program do?
If it was a desktop application, I would pop up a message box, saying "network is required", and exit the program.
I hear in WP exiting is not recommended; we don't often call Application.Current.Terminate().
Is there a way to suspend the application, return to the "desktop" and when users turned on Wifi, he can run my program and raises OnNavigatedTo again?
I know turning on Wifi automatically by the program or navigating to Setting page would be a good design. But I'm currently curious about suspending/minimizing the application.
No. There is no good way to programmatically suspend the app. You could hack it by launching another app, but that wouldn't be a very good user experience.
In your case I'd display a message that the app cannot continue without network access and wait for the network. The app isn't completely dead since the network may connect either on its own or by user action.
Flaky network connections are annoying enough without being compounded by the app exiting and users needing to restart it if they temporarily move in and out of a dead spot.
See How to detect network changes for Windows Phone 8

How to persist data correctly in Windows Store app

I want to save the data of Windows Store app to the file system (local folder) on suspension of the the app. On start of the app the persisted data is loaded from the file system and displayed in the app. This is working fine until the user closes the app and immediately restarts the app (because the suspension of the first app instance isn't yet finished).
Now, I'm not sure whether
I have to persist the data in another way or
I can wait until any other instance of my app is completely suspended.
Do you have any suggestions?
The problem is that after a close it take a few second before the suspending even is actually call and when the user restart, the previous instance of the app is killed so the suspending event is not even called and there is not much you can do to prevent that.
The recommendation is to save data incrementally as anyway the suspended event only have 5 seconds to complete.
The other possibility is to make your app target windows 8.1 as this issue as been fixed in windows 8.1:
In Windows 8.1 Preview, if the user closes an app and then immediately
restarts it, the closed app is given up to five seconds to complete
its termination before it restarts. In Windows 8, the app terminates
immediately upon restart.

How can I suspend my Windows 8 Pro app earlier than normal after being minimised?

I am building a Windows 8 Pro application and I would like the application to enter "Suspend" state immediately after losing focus (or being 'minimized')
This is for a kiosk application (won't actually be on the Store) where I want to relaunch/refocus the application when a user tries to hide it. So far, I can only 'refocus' it using a native C# app once the app has been killed (i.e. when the process does not exist in Process.GetProcessByName()). This is why I would like to kill the application-- the user should not be minimizing it so killing it is a cost the application can bear.
How can I get the application to terminate when it is minimized? I am wondering if it is possible to set the time-out period, or to intercept a general event in App.xaml.cs when the application itself has lost focus (then perhaps call App.Exit() terminate the process). I have tried the Application.Suspending event but takes too long to fire off. It takes about 10 seconds to fire off AFTER the application has been killed with ALT+F4.

Categories

Resources