使用WinRT不引发挂起事件

使用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不是逃跑。


有什么想法吗?


一只甜甜圈
浏览 588回答 3
3回答

慕丝7291255

我不知道你为什么要我给你看证据链接-不难找到MSDN博客->“如何调试流程生命周期事件”,它说:如果您想通过在每个处理程序中设置一个断点并按F5在VisualStudio中启动调试器来调试前面部分的代码,那么即使应用程序来回切换到屏幕上,您也将永远等待它们触发!原因很简单:在调试应用程序时,Windows不会将其挂起。

月关宝盒

我花了好几个小时才找到这个金块。TBF我并不知道我在寻找什么-我的症状(我在谷歌上搜索)是“Windows Phone应用程序崩溃,但不是在调试模式下调试”-也许留下这条评论将帮助Google链接到其他搜索同样事情的人这个很好的答案。这个答案不能解决问题,但它可以帮助您识别问题。&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP