HostLifecycleNotifications.WindowsPhone.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. #if WINDOWSPHONE7
  3. #if DEBUG_NO_AGENT_SUPPORT
  4. using Microsoft.Phone.Shell;
  5. #else
  6. using System.Reactive.PlatformServices.Phone.Shell;
  7. #endif
  8. namespace System.Reactive.PlatformServices
  9. {
  10. internal class HostLifecycleNotifications : IHostLifecycleNotifications
  11. {
  12. private EventHandler<ActivatedEventArgs> _activated;
  13. private EventHandler<DeactivatedEventArgs> _deactivated;
  14. public event EventHandler<HostSuspendingEventArgs> Suspending
  15. {
  16. add
  17. {
  18. _deactivated = (o, e) => value(o, new HostSuspendingEventArgs());
  19. var current = PhoneApplicationService.Current;
  20. if (current != null)
  21. current.Deactivated += _deactivated;
  22. }
  23. remove
  24. {
  25. var current = PhoneApplicationService.Current;
  26. if (current != null)
  27. current.Deactivated -= _deactivated;
  28. }
  29. }
  30. public event EventHandler<HostResumingEventArgs> Resuming
  31. {
  32. add
  33. {
  34. _activated = (o, e) =>
  35. {
  36. if (e.IsApplicationInstancePreserved)
  37. {
  38. value(o, new HostResumingEventArgs());
  39. }
  40. };
  41. var current = PhoneApplicationService.Current;
  42. if (current != null)
  43. current.Activated += _activated;
  44. }
  45. remove
  46. {
  47. var current = PhoneApplicationService.Current;
  48. if (current != null)
  49. current.Activated -= _activated;
  50. }
  51. }
  52. }
  53. }
  54. #endif