我在使用 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
没有运行。
有任何想法吗?