使用此代码,我可以确保只运行一个应用程序实例。但我无法使窗口从系统托盘恢复。我试过window.Show()但没有解决。
public class SingletonApplication : Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
{
public App application { get; private set; }
Telas.wndLogin window;
[STAThread]
public static void Main(string[] args)
{
new SingletonApplication().Run(args);
}
public SingletonApplication()
{
this.IsSingleInstance = true;
}
protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs eventArgs)
{
application = new App();
window = new Telas.wndLogin();
application.Run(window);
return false;
}
protected override void OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs eventArgs)
{
//todo:
}
}