I want to develop an app which downloads small files continuously when my app is not in the foreground and sends a notification if certain conditions are met.
Problem is that periodic agents have a scheduled interval of 30 minutes and a duration of 10 seconds, while resource-intensive agents have a duration of 10 minutes and need an external power source.
How could I do to achieve my goal ?
If you don't mind upgrading your Application to WP8.1 then you can use a very simple class to download a file in the background.
BackgroundDownloader class. There is really good example at the bottom of the page as well.
Useful Links if you want to understand more:
Transferring data in the background Describes the events of the BackgroundDownloader.
Periodic Tasks should really only do something very simple IMHO (that is why they have those restriction, not download something continuously) for example, Grab the latest news from a feed and update the Secondary Title.
Related
I really need to calculate responsiveness of my UI. Some suggested to use WpfPerf.exe (performance profiling tools for WPF). It works great however it does not have logging so it shows only last 1 minute of FPS as image.
However i need statistical information. The gui runs laggy so i need to record when exactly gui is refreshed. When there is no lag it should be refreshed each 0.5 seconds.
So i wonder anyhow i can record the time whenever gui is refreshed ?
.net 4.5.2 c# wpf
To record the time the GUI is refreshed. You may refer to
Why is Frame Rate in WPF Irregular and Not Limited To Monitor Refresh?
It may be out of topic. I would like to share what I do to improve my application last week.
Use visual studio performance and diagnostic, if available, to find bottleneck.
use BackgroundWorker to prepare data, instead of doing it in UI thread.
use data virtulization for dispalying huge amount data, for example million rows. This article provides an excellent solution for displaying millon rows data smoothly.
Hope It will help.
For my app I need to be able to let the user specify a given time and let my app run a background task at that specific time.
I understand that with wp8.1 a timetrigger background task can only run every 15 minutes. Is there anything I can do to ensure my app will run the task if the time has gone 10 minutes over the user's specified time?
For what I understand tasks are only executed in intervals multiple of 15 minutes in Windows 8.1 and 30 minutes in Windows Phone 8.1. Have a look here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh977059.aspx
I can not add a comment, that's why I share my experiences as an answer.
We had a similar problem in an application - we target the Windows Store 8.1 platform but our experiences can be relevant for you as the app cycles in the two platform are converged (http://msdn.microsoft.com/en-us/library/windows/apps/dn632424.aspx).
In our app we have to monitor streams and collect information. This logic has to be executed per minute what is not supported, as mentioned. That's why we use a simple Task with a CancellationTokenSource, and we start/stop the task in the app cycle-related events (Suspending, Resuming). This "solution" is not acceptable if the execution of the background logic is required when the app is suspended, too, but in our case this was not required.
There are apps on Android such as Tasker and Trigger that allows the user to set up some "Triggers" and the "Responses" that should execute when each trigger triggers.
The triggers could be, for instance: Connecting to a certain Wi-Fi, Arriving a certain location (Geo-Fencing), Plugging the earphone, tapping an NFC Tag and so forth.
I wonder if there's any way to to something like this on the Windows Phone platform. I have no background in developing for WPhones (even though i have a huge C# background), so i'm not sure whether the platform itself allows this sort of "background monitoring of sensors or, if there are such sensors (such as "headphone plug").
After a quick research, seems that access to some APIs are not allowed from Background Threads, i wonder if there's anything related to security here, or just an inability of the platform.
Is there any way to achieve what i want?
On Windows Phone 8 you can perform background processing, with Background Agents.
You can use Sceduled Taksto register a class containing a method that is called periodically, even when your app is not running. They are multipurpose and offer the greatest utility for extending your app to perform background activities.
You can surely display a message to the user, or fire an alarm or something, a message would be more suited, for location aware apps. Those registered as geographic location providers are able to continue running despite there being another app running in the foreground.
For the rest of your triggers, I'm not sure. You'll have to check the Sensors.
No, you can't hook any triggers or events. The only thing you can, as Pantelis said, is to create very limited PeriodicTask that may or may not be run every roughly 30 minutes and be constrained to max 25s of running time. This is deliberate platform limitation, AFAIK done mostly because of battery usage and security reasons.
If something can't be achieved by PeriodicTask, give it up. This is the most versatile background process, others are even more limited. This is by design to prevent daemons from taking over the phone.
I have the following scenario in mind:
I want to send (via serial port) some commands to a device. This device does send me back a continuous stream of data (max. 12000 values per second).
To control some settings I need some buttons to send commands to the device to start/stop/change settings before and during data stream. Also I want to have a real time plot of this data. I will filter this data of course. Also at certain timestamps there will be a signal which indicates that I want to cut out a certain window of the received data.
This means I will have two charts. I made already some progress using WPF but now when I interact (zoom/pan) with the lower chart, the upper one freezes noticeable. This is because both have do be refreshed very often!
Work (data receiving/filtering) is done using threads but the update of the plot has to be done within the ui thread.
Any ideas how to solve this issue? Maybe using multiple processes?
You should use Reactive Extensions. It was built for this kind of thing.
http://msdn.microsoft.com/en-us/data/gg577609.aspx
Requesting a clear, picturesque explanation of Reactive Extensions (RX)?
On this second link, although the topic is javascript, much of what it says is about Reactive Extensions and cross-applies to Rx in C#.
I'm making a similar WPF application with real-time waveforms (about 500Hz). I have a background threads that receives real-time data, a separate threads to process them and prepare the data for drawing (I have a buffer with the "size" of the screen where I put the prepared values). In the UI thread I draw the waveforms to the RenderTargetBitmap which is in the end is rendered to the Canvas. This technique allows me have a lot of real-time waveforms on the screen and have zoom and pan working without any problems (about 40-50 fps).
Please let me know if you need some technical details, I can later share them with you.
I think you have some code in the UI thread that is not optimized well or can be moved to the background thread.
Btw, do you use any framework for charts?
Edit
philologon is right, you should use Rx for real-time data, it simplifies code A LOT. I also use them in my project.
Its a commercial product but there is a real-time WPF chart which can handle this use-case and then some. Please take a look at the Tutorial below:
http://www.scichart.com/synchronizing-chartmodifier-mouse-events-across-charts/
There is a live Silverlight demo of this behaviour here:
Sync Multichart Mouse Silverlight Demo
And this chart should be able to handle zooming while inputting values at high speed:
Realtime Performance Demo
Disclosure: I am the owner and tech-lead of SciChart
I want to potentially update the tile of my WP8 app periodically - no more frequently than every hour or two. However, I don't want my app to have to be running for this background task to take place (will query a WAMS and, based on the returned results, update the WP8 app's tile).
Is this possible, or do background tasks (I found this tutorial on how to create one:
http://thesociablegeek.com/windows-8/livetiles/modifying-live-tiles-in-a-background-process/) require that the app that hosts them be running?
IOW, what I basically need is similar to a Windows Service, that his hosted by the OS, not a/my particular app.
Here's a guide how to use so called Background Agents in Windows Phone 7 or 8:
Background agents for Windows Phone
Basically you can schedule simple task to be executed every 30 minutes, even the main application is not running. There are system requirements on these tasks like memory cap constraint 6 MB for WP7 and 11 MB for WP8 tasks, run time of each task 25 seconds, and limited available APIs.
I would recommend that you code your tile update logic as a periodic task and then configure it to run in background. this way, you don't have to maintain your app running in background.
Hope this helps.