gpt4 book ai didi

win-universal-app - Application.Current.Exit() 和 OnSuspendingEvent

转载 作者:行者123 更新时间:2023-12-05 08:23:48 25 4
gpt4 key购买 nike

在通用 Windows 10 C#/Xaml 应用程序中,当我通过 Alt+F4 关闭我的应用程序时,OnSuspending 事件被触发。尽管当我调用 Application.Current.Exit() 时情况并非如此,尽管文档指出只要应用程序即将终止就会触发此事件。

为什么会这样?看起来不一致的行为导致我的应用程序出现错误。

最佳答案

Microsoft 的这张官方图片说明了 Windows 通用平台应用程序的应用程序生命周期:

Lifecycle

documentation of this lifecycle解释:

After an app has been closed by the user, it's first suspended and then terminated, and enters the NotRunning state.

此外,Microsoft 建议不要以编程方式关闭应用!
来自 "Guidelines for app suspend and resume" :

Don't include Close buttons or offer users other ways to terminate your app in its UI. Users should feel confident that the system is managing their apps for them. The system can terminate apps automatically to ensure the best system performance and reliability, and users can choose to close apps using gestures on Windows or through the Task Switcher on Windows Phone.

但是如果你...

close an app programmatically, the system treats it as an app crash.

因此,您的应用将从Running 状态直接进入NotRunning 状态。

如果您处理 CoreApplicationExiting 事件类。

关于win-universal-app - Application.Current.Exit() 和 OnSuspendingEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33364947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com