Windows 8.1 background task terminated when application is launched - windows-runtime

I'm encountering a strange issue when a background task is executing then the user launches the foreground application. If the user launches the app while the background task is executing, the background task is terminated. Is this normal or expected behavior?
The background task begins and ends with success in the following scenarios:
The foreground app is currently running
The foreground app is not running
I've read the following post as it seems to be the exact issue I'm experiencing. However, the responses don't apply since I already have a reference to the background task project. This is required for a background task to even work and be registered.
Update 3/16/2014
I've discovered that this may be more edge case than I originally anticipated. In the following scenario the application is launched successfully and the background task is not terminated.
Fresh boot of machine
Background task is manually triggered (currently triggered by InternetAvailable)
Launch Application
What I've discovered is that when the following steps are run the background task will terminate upon application launch
Launch application
Manually close application
Trigger background task
Launch application (application is displayed immediately as if it was suspended. Oddly enough when I run the application after closing it every other time the splash screen is always displayed. In this scenario when the background task is triggered the application seems to be in a suspended state)
Manually close application
Launch application
Again, I understand this is a very odd set of steps to reproduce this issue but if anybody is running across this or it is an expected behavior please let me know.
Thanks in advance.

Related

WinRT app closed due to suspend timing out when device is resuming from sleep

I've been dealing with a fault found during testing that I can't seem to get to the bottom of. I have a Windows 8.1 application running on a laptop on Windows 10. The user was using the application, left the laptop for a couple of hours, when they came back the application had disappeared and had lost the data that hadn't yet been saved. This has happened twice on the same machine.
Digging through the Event Viewer on the machine, it appears the following scenario happened:
Application was started
Device went into suspend
Device resumed
During the resume process, the following event appeared in the Event Log:
Package XXX+App was terminated because it took too long to suspend.
Running through the suspend mode using the Visual Studio tools it seems to take around 300ms to run the code that saves the current state.
I don't understand why the application would be suspending while the device itself was resuming. Could this be a case of the app suspend started before the device suspended, and when the device resumed it decided it'd had long enough? In which case what is the correct way to handle this?
Or is this something completely different? I'm not certain where to go with this and can't seem to find any documentation that covers the app suspend/resume in conjunction with a device suspend/resume.
Thanks

Using AS3 Timer & distriqt Notification ANE To Send Notifications While In Sleep Mode

I'm using the AS3 Timer class to sync data between a Flex Mobile app and a server ideally every 30 mins then send a local (distriqt) Notification to the user when action is required.
However, when the device goes into sleep / hibernate mode it seems to slow down, even stop the Timer. I've tried using a lower interval (5mins) but it still only works intermittently.
This is very hard to test as the behavior is different in debug / run modes.
Any suggestions?
Thanks.
Sounds like you might need to change your approach here. Background operation of applications is very different from the foreground.
Your application will run for a little while (depending on the current device memory load among other things) and will then enter a suspended mode, mainly to preserve the application's memory state.
There are some background mode exceptions to this, such as audio playback and location updates, however if you aren't performing these then Apple will most likely reject your application as part of the review process.
You can also investigate the executeInBackground flag on the NativeApplication. This allows a long running task to execute in the background, however this does not guarantee that the application would run in the background continuously.
You can read more here: http://blogs.adobe.com/airodynamics/2012/05/04/air-ios-background-behavior/
UIBackgroundModes: https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW22

Long-running task performed in foreground is suspended when app goes to background

When a user first opens my app, I need to download and install some content from a server before they can begin using the app. The problem is that this takes around 5 minutes on wifi, during which time the app goes into the background and the download is suspended.
Is there any way to either:
Prevent an windows app from entering the background while I perform my download
or continue peforming the task in the background (i.e. perform the task irrespective of whether the app is in the foreground or background)
Also, I don't want to use the BackgroundDownloadManager
Thanks
When the app is being suspended, all processes are stopped and and background task cancelled. Your last chance to do something is Suspending event - see more at MSDN.
In your case, when you need to download big file in the background - the mentioned BackgroundDownloader would be the best option - it's designed for such tasks. In other cases you will have to convince user to leave the app in the foreground (a message?), also take care about lockscreen (see DisplayRequest class).
I'm not also sure but maybe you will be able to use BackgroundTask (separate process), triggered with MaintanceTrigger - but then user will be able to download the file only in specific circumstances and probably not right away.

ApplicationIdleDetectionMode and WebBrowser functionality in WP8

In WP8, if we set
ApplicationIdleDetectionMode = IdleDetectionMode.Disabled
the app continues to run even when the screen is locked.
If, for instance, we have a WebBrowser in an app (which is actually active only when the app is in the foreground), and the above property is set as disabled:
Will the WebBrowser continue its execution even when the screen is locked (for example, playing an audio file).
Will the WebBrowser continue its execution even when the app is switched to the background.
Thanks.
As for running under lock screen - yes it should run, you can get more information from MSDN.
As I have tested once, WebBrowser is using BackgroundAudio to play (audio element), so it should also play under lock screen and probably in background (thought you should test it).
When the App goes to dormant state - all its processes are stopped MSDN:
When the user navigates forward, away from an app, after the Deactivated event is raised, the operating system will attempt to put the app into a dormant state. In this state, all of the application’s threads are stopped and no processing takes place, but the application remains intact in memory.
You should also watch out for Certification requirements, when usind AppIdleDetection - point 6.3 – Apps running under a locked screen.

Winrt BackgroundTask Executes

When adding a background task in WinRT with a trigger of SystemTriggerType.InternetAvailable
if the internet is available when the task is registered will if execute right then? or will the task wait for the internet to not be available and then available again to execute?
Or can I force execution of that background task when my app is active?
A backround task with SystemTriggerType.InternetAvailable will only start when Internet becomes available. If it's already available when the task is registered, it won't trigger.
If you need to execute that code even if internet is available all the time, the best thing would be to create another background task with TimeTrigger and SystemConditionType.InternetAvailable. You are allowed to set it to the minimum interval of 15 minutes.
If you also need to be able to execute the same code from your app immediately, then put the relevant code in a separate library and call it both from the background tasks and the application code.