HostLifecycleNotifications
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Core;
namespace System.Reactive.PlatformServices
{
internal class HostLifecycleNotifications : IHostLifecycleNotifications
{
private EventHandler<SuspendingEventArgs> _suspending;
private EventHandler<object> _resuming;
public event EventHandler<HostSuspendingEventArgs> Suspending {
add {
_suspending = delegate(object o, SuspendingEventArgs e) {
value(o, new HostSuspendingEventArgs());
};
WindowsRuntimeMarshal.AddEventHandler<EventHandler<SuspendingEventArgs>>((Func<EventHandler<SuspendingEventArgs>, EventRegistrationToken>)CoreApplication.add_Suspending, (Action<EventRegistrationToken>)CoreApplication.remove_Suspending, _suspending);
}
remove {
WindowsRuntimeMarshal.RemoveEventHandler<EventHandler<SuspendingEventArgs>>((Action<EventRegistrationToken>)CoreApplication.remove_Suspending, _suspending);
}
}
public event EventHandler<HostResumingEventArgs> Resuming {
add {
_resuming = delegate(object o, object e) {
value(o, new HostResumingEventArgs());
};
WindowsRuntimeMarshal.AddEventHandler<EventHandler<object>>((Func<EventHandler<object>, EventRegistrationToken>)CoreApplication.add_Resuming, (Action<EventRegistrationToken>)CoreApplication.remove_Resuming, _resuming);
}
remove {
WindowsRuntimeMarshal.RemoveEventHandler<EventHandler<object>>((Action<EventRegistrationToken>)CoreApplication.remove_Resuming, _resuming);
}
}
}
}