UWP: how to run a task without slowing down? - c#

i'm developing an uwp app in c# capable to play midi files. I created a ThreadPoolTimer to scan a tick of 1 ms and other ThreadPool to run an async task that launch the midi messages of files relative to the time scanned by tick. It works correctly however when i do some other operation with laptop it throw a slow down behaviour. Mainly when i turn the gui in background. I changed the ThreadPool.RunAsync() with a Task.Run() and it works better but i'm trying to understand what is the best way to do a real time app with uwp because i need to implement new tasks. Additionally, i want to change base priority of my app programmatically because it works better with high priority but i don't want to change it manually everytime.
Ho can i do this tasks? i'm searching on internet but i not found any useful information about this in uwp.
Thank you
Edit: I want to use this app for play music so i need to develop it with high performance feature. For this cause i need to launch it directly with high priority level.
maybe can i develop some library

Related

Xamarin iOS backgrounding app termination

I’m currently developing a timer app for android and iOS. I really care more about iOS for the time being, and even after following Xamarin’s documentation on backgrounding, using messaging center calls to the appDelegate.cs class and then launching a background task with the platform specific code, I’m still having my app terminated.
Is there any way to put an iOS app as a foreground service, like on android. Or is a background service still the way to go? I am trying to allow the user to set a timer up to 23 hours in advance and show count down.
To those interested, another strategy I found was just setting a notification to go off, regardless of if the app is running or not. Then, you can just handle persistence instead of trying to make the app keep running!
Good luck to everyone!

Is there a way to keep internet connections / sockets open after iOS forces app into sleep mode?

I'm developing a Xamarin app that uses location background modes to keep itself awake in the background, scan and report on iBeacons in its range over AMQP, and also make HTTPS requests to a log server.
This all works great, until a sustained period of time where the GPS location does not change and there are no changes to the radio frequency environment (i.e. no new iBeacons introduced, none taken away).
It appears that iOS puts the app into sleep mode (it's a slightly different sort of sleep mode to normal, as background modes are involved, so I don't see an OS callback for this). Moving the phone, or introducing new iBeacons wakes the phone up, but sometimes the app is no longer able to access the internet, using objects that were created before the app was sent to sleep. It appears as if the kernel is closing sockets.
Any ideas as to how I could diagnose this issue more effectively, or suggestions to how I can keep these sockets open, would be most appreciated.
Thank you for reading!

Debugging Background Task Event cancellation in Win RT (c#)

I'm working on a Win Phone 8.1 App that uses the background audio player, but I'm having trouble, particularly when it comes to the cancellation event. I want to debug it myself to learn but I can't seem to find a way to manually cancel the background task other than to pause and wait 5 minutes while the app is suspended, something impossible while debugging.
Is there a way to do so cleanly (ie. Not artificially increasing memory usage)?
There come two ways to my mind, both quite easy to do:
invoke BackgroundMediaPlayer.Shutdown from your code
while debugging, hit Start, find Music app, open, start playing an audio file - hence there can be only one Instance of MediaPlayer, yours will be cancelled.

BackGround Task not working in a window phone 8 beta app

I have created a Window phone 8 app. Which changes the lockscreen image and notification in around 30 sec randomly.
My code works well in the emulator and device. When I install it through the code. My problem is that when I have submitted the app to the store as a beta app. And now I install the app from the store the app don't work as it was working. The lockscreen content don't change it remains static. I have checked the settings background agents that app is running in the background tasks but not showing the result.
What could be the cause that app is running well from the code but not from the xap uploaded to the store.
Link of app is http://www.windowsphone.com/s?appid=00d47e34-a551-4c98-b2a6-32e10babdc2f
am I missing any capability that need to fixed.
Your suggestions are welcome.
Because your title says you are using a background task and you are trying to do something every 30 secs, I assume that you're using ScheduledActionService.LaunchForTest to trigger your background task and which then performs the updating.
ScheduledActionService.LaunchForTest is only supported in DEBUG builds as a way to aid testing. It is not possible to submit an app to the store that is built in DEBUG mode so this will not work.
It is not possible to create an app which will update so often in the background. To have such an app would, potentially, drain the battery really quickly and so provide a very poor experience to users.
The best you can do is to have the background agent run on a periodic schedule (approx. every 30 mins) or trigger the updates via push notifications. (But this wouldn't work for the lock screen image.)

Control application execution under any condition in WP8

I'm trying to build a basic tracking app for Windows Phone 8. However I can't figure out which model to use. The app shall log the location in a definable interval (e.g. 5 sec or even 2 hours).
If I develop the app as an foreground application the tracking will stop if the user opens another program, the screen locks (you can configure the app to continue running under the lock screen), or you reveice a phone call. Overall the risk of the app not being executed is to high.
There are also background tasks that are scheduled by the OS, and are only allowed to run a few seconds or minutes depending on the current state of the phone. Is there some workaround to schedule the background task execution as defined by the user? E.g. the Email client can be set to fetch emails every 15 minutes, therefore there must be some way.
The thrid option would be using the push notification service. This however seems stupid as some third party Microsoft server has to be involved and other limitations may apply. And more importantly, the app must run to receive the notification.
What is best practise on this? I don't care about battery drain as long as the app works as wanted. Similar solutions must exists for tiles that shall be updated more frequently (30 minutes or even more seems awfully long)? Am I missing something?
A basic app that can call it's own sleep would be great, but if it get's killed after a few seconds, that won't do it. Or does sleep time not count?
I'm afraid you can't do anything to make sure about your app execution.
Standard foreground application is always less important than things like incoming phone call, so you have to assume that it can be paused or stopped at any time. You also can't force user to use your app - that's why user is able to exit the app at any time.
Background execution on Windows Phone cannot be made permanent - that's how that OS is designed. And mail application is not a good example because it's a build in app. It was made as a part of that system, so it has another set of rules (if any).
I don't really see a way to do that using Push Notifications. But even if there is one, I'm sure it's not how that feature should be used.

Categories