gpt4 book ai didi

uwp - 如何检测 UWP 的退出

转载 作者:行者123 更新时间:2023-12-04 02:56:51 26 4
gpt4 key购买 nike

有什么方法可以检测当前的 UWP 要退出 ? (由用户关闭或终止进程)

我想向服务器发送一些关于应用程序将断开连接的请求,还想在退出之前保存一些数据。

最佳答案

无法检测这种情况或阻止用户终止您的应用程序。如果你想在退出前保存状态或做一些事情,使用 Suspending event :

The Suspending event is the only indication your app will receive prior to termination (if it happens). Because of this, you should store enough session state (such as the current article being read or the current movie playback position) to recreate the exact same experience during activation. The guidance for content creation apps is to save a user’s work early and often but also commit one final save during Suspending. Saving data prior to suspension is useful because the Suspending event handler has only 5 seconds to complete its operation.



只记得有限的时间。

事实上,还有另外两个事件会被触发(在移动情况下,当用户按住后退按钮并转到任务切换器时):Window.VisibilityChanged 和 Windows.Activated,但是当用户更改应用程序、显示提示和等等 - 并且没有办法区分这些情况。

关于uwp - 如何检测 UWP 的退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37693804/

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