简体   繁体   English

C#在运行时打开文件关联

[英]c# open file association at runtime

(Sorry for my bad english) (对不起,我的英语不好)

Hi I have a problem. 嗨,我有问题。

I need to open the associated files already in my program while it is running. 我需要在程序运行时打开程序中已有的关联文件。

If we take example visual studio, when I opened the ide and I double-click on a file example test.cs 如果以Visual Studio为例,当我打开ide并双击文件示例test.cs时

Do not opening a new application, But he added a tab with the new file. 不要打开新的应用程序,而是他在新文件中添加了一个标签。

And 'possible to do such a thing? 而且“有可能做这样的事情吗?

As you've observed, Windows Explorer will try to launch a new instance of your app when you double-click a file associated with your application. 如您所见,当您双击与应用程序关联的文件时,Windows资源管理器将尝试启动应用程序的新实例。 You can't change that. 您无法更改。 What you can do is have the new instance check whether an instance is already running and, if so, tell the running instance to load the file. 您可以做的是让新实例检查实例是否已在运行,如果已运行,则告诉正在运行的实例加载文件。 There are lots of ways to establish this sort of communication. 建立这种交流有很多方法。 You could listen on a port, periodically check for a file in a particular location, etc. How to do it is up to you. 您可以在端口上侦听,定期检查特定位置的文件,等等。如何操作取决于您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM