OnSuspending event fired during app initialization while minimized - c#

I have a UWP app that is configured to auto start at Windows boot via the Startup Apps on Windows 11.
On some PCs - and it is unclear for what configurations - the app starts minimized at Windows boot, and receives a OnSuspending event while it is still initializing (during or just after the OnNavigatedTo event, and before the OnLaunched event). This OnSuspending event breaks the initialization sequence of the app which keeps running but fails to execute its task.
So a successful sequence of events looks like:
OnActivated
OnNavigatedTo
OnBackgroundActivated
A failing sequence looks like:
OnActivated
OnNavigatedTo
OnSuspending
OnBackgroundActivated
I can't see on my code any logic error that would lead to this OnSuspending event. Is there a possibility that Windows sends this event out of the blue at this boot time, maybe depending on other processes being started at the same time? Or should I look further in my code for any error that leads to this suspension?

OnSuspending event fired during app initialization while minimized
It's by default, please refer to StartupTask document If the user consents, the UWP app will then start on startup or user log in. Note that UWP startup apps will start minimized. when app minimized, the OnSuspending will be called (by design). if this behavior cause app initialization fail, please take care of OnSuspending event, and saving necessary application state.

Related

Cross-platform C# (Xamarin) - Execute Tasks while "Asleep" on iOS

We're writing a cross-platform C# "Xamarin" application; right now we're just targeting the iPad. The application has two features relevant to this question:
The app requires that the user authenticate to the app (in addition to logging onto the iPad)
The app connects to a remote device over Bluetooth
So the question becomes, what happens when the user switches to another app, which results in our app's OnSleep() being called. In OnSleep() we could immediately disconnect Bluetooth and log out the user, but that seems like poor usability, especially if they are just quickly checking some alarm that triggered or an instant message that came in.
For the sake of usability, we're thinking to have a 1-minute timeout; if the user does in fact pop out and quickly pop back into the app, we'd like things to simply continue on without any loss of communication or re-authentication.
If, in OnSleep(), I set up a timer using Xamarin.Forms.Device.StartTimer(), that timer does not fire while the app is "asleep".
What does it take to have a small background task/thread/process execute, even while the app is asleep? Something that simply waits 1 minute, and then shuts down the Bluetooth communication and sets a flag indicating re-authentication is needed?

Windows Phone 8.1 Silverlight - Toast Notification Launch Causes App to Restart

I'm working on Toast Notifications for my WP8.1 Silverlight App that are activated via a background process. Whenever I tap on the Toast when it appears (or tap on it from the Notification Action Center), it always restarts the app. It navigates to the main page for a split-second and I notice that the Bing Map I have embedded in the Mainpage is blank, then it restarts. I specify in the toast for it to go to the mainpage as follows (with a parameter):
((XmlElement)toastNode).SetAttribute("launch", "#/MainPage.xaml?conversation=12345");
Other aberrant behavior is
When debugging, and the app is invoked from the Toast the main page 'onNavigatedTo' event gets hit twice both times with the parameter specified from the toast.
When the app relaunches itself after being invoked from the Toast, and I go back to the Start Screen and tap the Live Tile to be taken back to the app, it again needs to restart itself. This never happens if I launch the app normally from the Live Tile or Application Icon.
The debugger isn't catching anything. Could it be something to do with the app being tombstoned, or the app 'Applicated_Activated' event not being hit up properly?

WP8 timer app under lock screen

I have app with dispatcher timer. User set some interval(for example 30 sec) and press button start. App Each 30 sec play sound. All work ok. But when User lock phone timer stopped and nothing played. Can I play sound each 30 sec when phone is locked?
It is possible to keep the app running under lock screen.
Using Idle Detection, you can keep the app on, although screen is locked. Actually, it is not running in background, but in the foreground. Just the screen is locked. So, be careful not to drain user's battery.
You have to set the PhoneApplicationService.ApplicationIdleDetectionMode property to Disabled, for example in InitializePhoneApplication() method in App.xaml.cs:
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
Note that there are special certification requirements for this type of apps. Refer to section 6.3 (Apps running under a locked screen) of the following page:
Additional requirements for specific app types for Windows Phone
yes.
sure..
You can use the Scheduled Task Agent in windows phone.
using the Scheduled Task Agent, when you app is not running or stopped (not in background).
you can fire your Events.
For that you have to add the scheduled task agent into your project.
And in the ScheduledAgent.cs file find the OnInvoke method and put your code here.
this method performs the task in Background. (Means the code is executed when your phone is locked).
for more Reference click here Implement background agents for Windows Phone
I hope you get the destination. Now, just put that code into your application and its working.

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.

Session variable in C# desktop application?

I am developing a C# a stand alone single user desktop application that requires the user to login to the application. I want to ensure that when there is no activity for 5 minutes or so the application will prompt the user to login again. I have several solution in mind to do this but there do not seem efficient. Previously while doing web programming i was able to do this kind of feature using session variable are there are similiar kind of features in C# that can be used for desktop application.
One way to do this is to set a 5-minute timer that is always running, and logs the user out when it ticks. Then you can have any activity restart the timer from the beginning.
If this is a WinForms app, you can have your top-level forms implement IMessageFilter. In your PreFilterMessage function you would restart the timer and return false for messages that indicate activity (WM_KEYDOWN, WM_MOUSEMOVE, etc.) to let everything get processed normally.
You can always add a trigger to auto-logout within a Windows Forms Application. Here is a link with examples with an accepted answer
How can I trigger an auto-logout within a Windows Forms Application?
To monitor user activity, you could create a custom Form-based class
from which your application forms will inherit. There you can
subscribe to the MouseMove and KeyDown events (setting the KeyPreview
property to true), either of which will be raised whenever the user is
active. You can then create a System.Threading.Timer, with the due
time set to 30 minutes, and postpone it using the Change() method
whenever user activity is detected.
No, but session state is just a list of variables to help overcome the stateless nature of web applications. Since desktop applications are not stateless, there's no need. I'd just use a simple timer or something similar and log the user out after 5 minutes of inactivity.

Categories

Resources