【发布时间】:2014-10-30 13:01:44
【问题描述】:
考虑:
public partial class App : Application
{
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
private Mutex myMutex;
protected override void OnStartup(StartupEventArgs theArgs)
{
bool aIsNewInstance = false;
myMutex = new Mutex(true, "Testing", out aIsNewInstance);
if (!aIsNewInstance)
{
App.Current.Shutdown();
Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
IntPtr pointer = FindWindow(null, "Testing");
App.Current.Shutdown();
ShowWindow(pointer, 1);
break;
}
}
}
如何防止我的应用程序的第二个副本在我双击图标时启动,而是让已经运行并最小化到托盘应用程序中以显示窗口?
【问题讨论】:
标签: c#