using System.Diagnostics; using System.Windows; using Microsoft.Phone.Scheduler; using System.Reactive.Linq; using System; namespace WindowsPhoneAgent8 { public class ScheduledAgent : ScheduledTaskAgent { /// /// ScheduledAgent constructor, initializes the UnhandledException handler /// static ScheduledAgent() { // Subscribe to the managed exception handler Deployment.Current.Dispatcher.BeginInvoke(delegate { Application.Current.UnhandledException += UnhandledException; }); } /// Code to execute on Unhandled Exceptions private static void UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { if (Debugger.IsAttached) { // An unhandled exception has occurred; break into the debugger Debugger.Break(); } } /// /// Agent that runs a scheduled task /// /// /// The invoked task /// /// /// This method is called when a periodic or resource intensive task is invoked /// protected override void OnInvoke(ScheduledTask task) { //TODO: Add code to perform your task in background Observable.Return("").Delay(TimeSpan.FromSeconds(1)).Subscribe(_ => { NotifyComplete(); }); } } }