为什么Application.Restart()不可靠?不可靠、Application、Restart

2023-09-02 10:19:57 作者:枕边书

使用方法 Application.Restart()在C#中应重新启动当前应用程序:但似乎这并不总是工作

Using the method Application.Restart() in C# should restart the current application: but it seems that this is not always working.

还有一个原因是对于这一问题,有人可以告诉我,为什么它不工作的所有时间?

Is there a reason for this Issue, can somebody tell me, why it doesn't work all the time?

推荐答案

有可能是一个很大的原因。这并不是说该方法不起作用;相反,很多时候程序员忘记,他们已经把东西在自己的code,它会阻止自动关闭,或启动应用程序。举两个例子:

There could be a lot of reasons for this. It's not that the method doesn't work; rather, many times programmers forget that they've put something in their code that would stop the application from automatically shutting down, or starting up. Two examples:

在窗体上的Closing事件可以停止一个应用程序的停机时 如果你正在做检查一个已经运行的过程中,老人们可以不关闭不够快,让新的启动。

检查$ C $下这样的陷阱。如果您看到在一个空白的应用程序这种行为,那么这是更可能是比你的code中的实际功能有问题。

Check your code for gotchas like that. If you're seeing this behaviour within a blank application, then that's more likely to be a problem with the actual function than your code.