9

I want to open files, which are doubleclicked in Explorer, in the same instance of my .Net application, e.g. in a new tab. How can I do this?

For now each file starts new instance of my application. Many programs can open files in the same instance, for example, Opera and Notepad++, so there is an easy way for sure.

Alexei
  • 127
  • 4

4 Answers4

4

You may take a look at this post which illustrates a technique that could be used to have a single instance WinForms application.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
2

In case you want to do the same, but in WPF rather than WinForms, the howto is explained here: What is the correct way to create a single-instance application?

Community
  • 1
  • 1
Benlitz
  • 1,952
  • 1
  • 17
  • 30
1

Might be an easier way to do it but the way I've done it is that if an instance is started with a filename as a parameter then it checks if there are any other instances and if so passes on the filename to that instance and the close itself down.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
0

Example using TCP-sockets: http://pieterjan.pro/?a=Projecten_csharp_DrawIt.php

  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"