如何重新启动我的 C# 移动应用程序?

发布于 2024-12-10 20:06:05 字数 555 浏览 0 评论 0原文

我阅读了许多论坛和链接,例如:

How do I restart my C# WinForm 应用程序?

但所有这些都是针对 Windows 的,而不是针对移动设备的。当我捕获未处理的异常时,如何重新启动我的移动应用程序。现在,当我捕获未处理的异常时,应用程序已关闭,但我不想关闭它,所以我想重新启动它。

这不起作用:

ProcessStartInfo s = new ProcessStartInfo();
            s.FileName = Assembly.GetExecutingAssembly().GetName().CodeBase;
            s.UseShellExecute = false;
            Process.Start(s);

我正在使用 Windows Mobile 6.1 和 CF 3.5

I read many forums and links like:

How do I restart my C# WinForm Application?

but all this are for windows not for mobile. How can i restart my mobile application when i catch unhandled exception. Now app is closed when i catch unhandled exception but i do not want to close it so i want to restart it.

This not working:

ProcessStartInfo s = new ProcessStartInfo();
            s.FileName = Assembly.GetExecutingAssembly().GetName().CodeBase;
            s.UseShellExecute = false;
            Process.Start(s);

i am uisng windows mobile 6.1 and CF 3.5

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦途 2024-12-17 20:06:05

WinMo 内置了一种机制来防止应用程序的多个实例运行,因此使用 Process 类调用自己将简单地启动 shell 终止的实例。您必须解决这个问题,P/Invoke CeRunAppAtTime 或创建一个单独的看门狗进程,确保您的应用进程始终运行,如果检测到它已经消失,则启动一个新实例。预先警告 CeRunAppAtTime 无法将应用程序安排到未来 11 秒以内,因此会出现延迟。

WinMo has a mechanism baked in to prevent multiple instances of an app from running, so calling yourself with the Process class will simply launch an instance that the shell terminates. You have to work around that, P/Invoke CeRunAppAtTime or create a separate watchdog process that makes sure your app process is always running, launching a new instance if it detects it is ever gone.. Be forewarned that CeRunAppAtTime can't schedule an app for less than 11 seconds into the future, so there will be a delay.

樱花坊 2024-12-17 20:06:05

你不应该。最好的方法是首先修复导致异常的错误来防止该异常。

但是,如果您真的、真的、真的需要因崩溃以外的任何其他原因重新启动应用程序,那么您可以在后台启动另一个进程以及您的应用程序,该进程会监视应用程序是否仍在运行并使用 Process 启动它。如果没有,请再次 Start()。

(如果您的应用程序设置为在设备上自动运行并且您的设备支持它,这不太可能,因为它是 Windows CE 的东西,但为什么不呢 - 您也可以 创建看门狗定时器以在需要时重新启动整个设备。)

但是一直重新启动应用程序(假设每天一次)会造成破坏这用户体验,也是用户的信任。所以你应该修复异常。

You shouldn't. The best approach is to prevent that exception with fixing the bug that causes it in the first place.

But if you really, really, really need to restart your application for any other reason than crashes, then you can start another process in the background along with your application that watches if the application is still running and starts it with Process.Start() again if it doesn't.

(If your application is set to run automatically on the device and your device supports it, -which is not very likely since it's a Windows CE thing, but why not- you can also create Watchdog timers to restart the entire device if needed.)

But restarting an application all the time (let's say once a day) ruins the user experience and also the user's trust. So you should fix the exception instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文