Windows sleep even for UWP apps - c#

In my app I have UP and DOWN channels which continuously listen for Audio stream.
I want to know that In windows is there any event which will tell me that machine is now going to sleep state (not sign-out because machine will go to sleep after sign-out based on the user settings) so that i can suspend the channels and once machine wake-up(Not sign-in because machine wake up before the sign-in even) then i can resume it again.
Something similar to Cortana
Thanks in advance.

There's no 'sleep' relevant APIs for you to detect if the windows will go to sleep in UWP.
If you check the Windows 10 universal Windows platform (UWP) app lifecycle, you will find that Suspending and Resuming are the right events to listen to.

Related

RequestAccessKindAsync from Desktop Bridge

I have Win32 desktop bridge application that uses background task to receive push notifications from WNS. I use UWP background task APIs over C++-WinRT
I'd like to be able to receive push notifications even when OS is in sleep so that it wakes up and the app handles push notification. By default OS does not wake up. It did only after manually changing settings value in System->Battery->See which apps are affecting your battery life->Click my app ->Uncheck Let Windows decide option (by default it is always checked) and check Allow the app to run background taks. Now I'd like to do this is manual work on code for better user experience.
RequestAccessKindAsync API allows to let user to change above setting value by showing popup notification to the user and I could do it without any problem in UWP C# sample app. But same code does not show pop notification from my desktop bridge over C++-WinRT. It simply returns false value for below code
auto result = co_await BackgroundExecutionManager::RequestAccessKindAsync(BackgroundAccessRequestKind::AlwaysAllowed,
L"App needs to use background to catch push notifications while device is in sleep");
Can anyone confirm that RequestAccessKindAsync API works from desktop bridge? If not then how I can make sure OS and the app will always be able to wake up from sleep when it receives push notification?
UPD: Raised request to enable this API from desktop brige here
This is a missing feature. When we designed this API a couple of releases ago we didn't consider desktop bridge apps would be calling it - but clearly there is a use case for supporting this. I have notified the team about this gap, but I'd also encourage you to log a feature request here: https://wpdev.uservoice.com/
Two possible workarounds:
(1) you could add a dummy/empty UWP foreground app to your desktop bridge app. You can then launch this on startup and request the background access from there. This will be a bit ugly, but you could make it look like a splash screen :-)
(2) you can instruct the user to go into the Settings app to set your app to always allowed. You can help them do that with a deep link to the battery save settings, but they will still need to manually flip the switch.

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?

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 do I receive power resume messages in Windows 8?

I have written a C# application that monitors a device attached to an ARM tablet running Windows 8. The application needs to detect when the tablet is resuming from sleep, so that it can send a command to the attached device.
I have tried monitoring the Microsoft.Win32.SystemEvents.PowerModeChanged event, as per this question.
I have tried watching for WM_POWERBROADCAST messages, as per this question.
In both cases the application works fine on my Windows 7 desktop development PC. However, neither approach works when I run the application on my Windows 8 ARM tablet.
Do I need to watch for a different message in this case? Is there something else I could try to work around this problem?
UPDATE: I have since found that when I plug or unplug mains power I do actually get a WM_POWERBROADCAST message (power status change). I also get a SystemEvents.PowerModeChanged event. However I am still not receiving any suspend or resume power messages when going through a suspend/resume cycle.
UPDATE #2: I have since found a workaround for my particular situation that does not rely on power messages. But thanks to those who took the time to answer/comment.

run task on specific time in windows phone 7

Can we run some task on specific time in background if my application is running or on dormant state. Is this possible in windows phone 7.5 Mango. If Its not possible then any work around with the help of push notifications.
If you are not the currently active application in Windows Phone your application is being tombstoned, which means that some of your state is saved and your application is halted (e.g. there is no code running for your application anymore).
Therefor you can not create code that allows your application to do anything at a specific time, without using push notification.
Even with push notification your options are very limited. It realy depends on what you want to happen when a notification arives.

Categories

Resources