打开一个文件在已经运行的应用程序 [英] Opening a file in an application that is already running

查看:223
本文介绍了打开一个文件在已经运行的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它设置,所以如果你打开一个文件,它启动我的应用程序,并把它添加到启动参数。但我怎么能做到,所以如果我双击它加载它是已经运行的应用程序的文件?而不加载每个文件到它自己的应用程序的实例。

I have it set so if you open a file, it launches my application and adds it to the start-up arguments. But how can I make it so if I double click on a file it loads it in the application that's already running? Rather than loading each file into it's own instance of the application.

推荐答案

互斥是要你要有的一个实例。应用

Mutex is want you need to have a single instance of the application.

bool createdNew = true;
using (Mutex mutex = new Mutex(true, "MyApplicationName", out createdNew))
{
if (createdNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}

您可以查阅本的 LINK 了解详细信息。

You can refer this LINK for detailed information.

这篇关于打开一个文件在已经运行的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆