我在使用WinRT时遇到了一个问题,无法在Windows Phone 8.1上挂起事件,它没有触发。我不知道为什么。这是我的代码:
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
InitializeComponent();
Suspending += OnSuspending;
#if DEBUG
this.displayRequest = new DisplayRequest();
#endif
}
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">
/// The source of the suspend request.
/// </param>
/// <param name="e">
/// Details about the suspend request.
/// </param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
deferral.Complete();
}
我在var deferral = e.SuspendingOperation.GetDeferral();
这一行设置了断点,并使用Visual Studio进行了调试。然后我按下手机上的启动按钮,运行了另一个应用程序并等待约10秒钟,但是OnSuspending
没有运行。
有什么想法吗?