使用WinRT不引发挂起事件
我在WindowsPhone 8.1上使用WinRT挂起事件有问题,它不会触发。我也不知道原因。这是我的密码:
/// <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();并使用VisualStudio对其进行了调试。然后我按下手机上的“开始”按钮,运行另一个应用程序,等待大约10秒。OnSuspending不是逃跑。
有什么想法吗?
慕丝7291255
月关宝盒
相关分类