How to open related files in a single application instance

I want to open files that are double-clicked in Explorer in the same instance of my .Net application, for example. in a new tab. How can i do this?

Now each file launches a new instance of my application. Many programs can open files in a single instance, for example, Opera and Notepad ++, so there is an easy way.

+7
c #
source share
4 answers

You can take a look at this post , which illustrates a technique that can be used to apply a single instance of WinForms.

+3
source share

Perhaps this will be an easier way to do this, but the way I did it, if the instance is started with the file name as a parameter, then it checks if there are any other instances, and if so it is passed by the file name the instance and close yourself.

+1
source share

If you want to do the same thing, but in WPF and not in WinForms, this explains how: What is the correct way to create a single-instance application?

+1
source share

An example of using TCP sockets: http://pieterjan.pro/?a=Projecten_csharp_DrawIt.php

  • run TCPListener in the form
  • connect TCPClient in the master instance of the second instance
  • Submit ActivationArguments over a TCP connection to the form

It works for several files at once and even for several files for the first time (when the application is not already running)

The most important blocks of code are:

  • The MainForm constructor (Hoofdscherm), where the server starts, and the port number is written to the file. The first file also opens.
  • The main function (Program.cs), where the second, third, instance connects to the TcpListener in the first instance and sends the file name through the socket

Source code is available on the Broncode button.

0
source share

All Articles