暂停事件不加使用的WinRT [英] Suspending event not raising using WinRT

查看:182
本文介绍了暂停事件不加使用的WinRT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用的WinRT在Windows Phone 8.1暂停事件的一个问题,它不火。我不知道为什么。这是我的code:

I'm having a problem with suspending event on Windows Phone 8.1 using WinRT, it does not fire. I don't know why. This is my code:

/// <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延期= e.SuspendingOperation.GetDeferral()断点; 并与Visual Studio调试它。然后我pressed我的手机上的启动按钮,跑到另一个应用程序,等待大约10秒。 OnSuspending 没有运行。

I set a breakpoint on the line var deferral = e.SuspendingOperation.GetDeferral(); and debugged it with Visual Studio. Then I pressed the start button on my phone and ran another app and waited about 10 seconds. OnSuspending is not running.

任何想法?

推荐答案

暂停事件不会触发,而你正在调试(但在运行你的App正常的,它会解雇你从App导航离开刚过),因为它是还表示,在这个博客

Suspending event won't fire while you are debugging (but while running your App normal, it will fire just after you navigate away from the App) as it is said also at this blog:

...你将永远等待这些触发,即使您的应用程序来回切换屏幕!原因很简单:当一个应用程序正在调试,Windows将不会将其挂起

...you will wait forever for these to trigger, even though your app switches back and forth to the screen! The reason is simple: while an app is being debugged, Windows will not suspend it.

请注意,这可能会导致一些奇怪的行为的应用程序,当有一些错误的挂起的事件 - 例如,如果您传入的 Frame.Navigate 的一些复杂的类方法并使用的 SuspensionManager 的。在调试应用程序将只是正常工作(无悬浮物),但会崩溃没有调试模式。

Note that this may lead to some weird app behavior, when there is something wrong in Suspending event - for example if you pass some complex class in Frame.Navigate method and you use SuspensionManager. While debugging your app will work just fine (no suspension), but will crash without debug mode.

要测试你的应用程序的行为,你将不得不的调用的的的挂起的manuallt,打开(或设置可见)的调试位置的工具栏Visual Studio中,在那里你会找到一个下拉Lifecyce事件中,选择有<大骨节病>暂停,然后返回应用程序 - <大骨节病>恢复

To test how your App behaves, you will have to invoke the Suspending manuallt, open (or set visible) Debug location toolbar in Visual Studio, there you will find a dropdown Lifecyce events, choose there Suspend, and then to return the App - Resume.

这篇关于暂停事件不加使用的WinRT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆