ScheduledAgent.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Diagnostics;
  2. using System.Windows;
  3. using Microsoft.Phone.Scheduler;
  4. using System.Reactive.Linq;
  5. using System;
  6. namespace WindowsPhoneAgent8
  7. {
  8. public class ScheduledAgent : ScheduledTaskAgent
  9. {
  10. /// <remarks>
  11. /// ScheduledAgent constructor, initializes the UnhandledException handler
  12. /// </remarks>
  13. static ScheduledAgent()
  14. {
  15. // Subscribe to the managed exception handler
  16. Deployment.Current.Dispatcher.BeginInvoke(delegate
  17. {
  18. Application.Current.UnhandledException += UnhandledException;
  19. });
  20. }
  21. /// Code to execute on Unhandled Exceptions
  22. private static void UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
  23. {
  24. if (Debugger.IsAttached)
  25. {
  26. // An unhandled exception has occurred; break into the debugger
  27. Debugger.Break();
  28. }
  29. }
  30. /// <summary>
  31. /// Agent that runs a scheduled task
  32. /// </summary>
  33. /// <param name="task">
  34. /// The invoked task
  35. /// </param>
  36. /// <remarks>
  37. /// This method is called when a periodic or resource intensive task is invoked
  38. /// </remarks>
  39. protected override void OnInvoke(ScheduledTask task)
  40. {
  41. //TODO: Add code to perform your task in background
  42. Observable.Return("").Delay(TimeSpan.FromSeconds(1)).Subscribe(_ =>
  43. {
  44. NotifyComplete();
  45. });
  46. }
  47. }
  48. }