Opening a “known file type” into running instance of custom app - .NET

前端 未结 5 1708
情歌与酒
情歌与酒 2020-11-30 06:56

How would you open a file (that has a known file/app association in the registry) into a \"running instance\" of the application it\'s supposed to open in? An example would

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 07:36

    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"

提交回复
热议问题