public class Startup
{
[STAThread]
public static void Main(string[] args)
{
SingleInstanceApplicationWrapper wrapper = new SingleInstanceApplicationWrapper();
wrapper.Run(args);
}
}
public class SingleInstanceApplicationWrapper :
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
{
public SingleInstanceApplicationWrapper()
{
// Enable single-instance mode.
this.IsSingleInstance = true;
}
// Create the WPF application class.
private WpfApp app;
protected override bool OnStartup(
Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
{
string extension = ".testDoc";
string title = "SingleInstanceApplication";
string extensionDescription =
WPF之单例模式
最新推荐文章于 2024-09-09 09:20:07 发布
该博客介绍了如何在WPF应用中实现单例模式。通过`SingleInstanceApplicationWrapper`类,结合`WindowsFormsApplicationBase`,确保应用程序只能有一个实例运行。在启动时,检查是否有已打开的实例并处理命令行参数,以打开指定文档。同时,提供了文件关联的注册方法。
摘要由CSDN通过智能技术生成