如何重新启动一个实例WinForms应用程序 [英] how do I restart a single instance winforms application
本文介绍了如何重新启动一个实例WinForms应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我使用
Application.Restart();
的问题是,检查了几个星期后显示,有运行6左右的实例。
the problem is that a inspection a couple of weeks later shows that there are 6 or so instances running.
我试图用
bool IsOwned;
Mutex m = new Mutex(true, Name, out IsOwned);
if (!IsOwned)
Environment.Exit(0);
但这并没有因为出于某种原因在最近停止实例仍然可见...或者至少这是我的理解,因此应用程序没有reatart。
But this didn't work as for some reason the recently stopped instance was still visible...or at least that's my interpretation and as a result the application didn't reatart.
我在哪里出了错?
推荐答案
请确保您的应用程序退出事件挂钩,释放互斥锁,并关闭它的方法。
Make sure that you hook on application exit event a method that releases the mutex and closes it.
这篇关于如何重新启动一个实例WinForms应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文