且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#中单实例应用程序中的多个文件

更新时间:2023-11-22 22:10:28

您没有提供任何相关信息,这些信息有助于查看您的应用程序中缺少的内容。但是您需要了解单实例行为是一回事,将数据从一个实例的命令行传递到另一个实例与此相关,但是有些不同。最有可能的是,您实现了单实例行为,并且根本无法处理您的文件。我不知道你为什么认为没有你的参与就应该这样做。我想如果你确实处理了你的文件,你会在你的问题中提到你尝试过的。



我有一个非常强大的解决方案,结合了两个功能使用同一设施。我在过去的答案中解释了所有的想法:

自定义Windows右键单击命令启动多个实例

仅向一个流程实例输入多个命令



另请参阅:

在已经打开的程序中打开文件 [ 2 ],

在已打开的程序中打开文件 [ 3 ]。



-SA
You did not provide any relevant information which would help to see what you are missing in your application. But you need to understand that single-instance behavior is one thing, and passing data from command line of one instance to another instance is related to that, but something very different. Most likely, you implemented single-instance behavior and simply did nothing to handle your files. I have no idea why did you assume that it should happen without your participation. I guess if you did take care of handling your files, you would mention what you tried in your question.

I have a very robust solution which combines both features using the same facility. I explain all the ideas in my past answers:
Custom Windows right-click command launching multiple instances,
Enter multiple commands to only one process instance.

See also:
Open File in already Open Program [2],
Open File in already Open Program [3].

—SA


使用TCP套接字的示例



1.启动TCPListener在表格上

2.在第二个实例的主要部分连接TCPClient

3.通过TCP连接发送ActivationArguments到表格



同时适用于多个文件,甚至第一次用于多个文件(当应用程序尚未启动时)



最重要的代码块是:



1. MainForm(Hoofdscherm)的构造函数,它启动服务器并将端口号写入文件。第一个文件也被打开。

2. Main-function(Program.cs),其中第二个,第三个......实例在第一个实例中连接到TcpListener并通过它发送文件名插座



源代码可在RAR格式的Broncode按钮上找到
Example using TCP-sockets

1. start TCPListener on the form
2. connect TCPClient in the main of the second instance
3. Send ActivationArguments through the TCP-connection to the form

Works for multiple files at once as well, and even for multiple files at the first time (when application not started yet)

The most important code blocks are:

1. The constructor of the MainForm (Hoofdscherm) where the server is started and the port number is written to a file. The first file is opened as well.
2. The Main-function (Program.cs) where the second, third, ... instance connects to the TcpListener in the first instance and sends the filename through the socket

The source code is available on the button "Broncode" in a RAR-format