Introduction

edit

Meziantou.Framework.SingleInstance provides the SingleInstance class: it tells an application whether it is the first running instance, and lets the next instances send their command-line arguments to the first one before they exit.

A typical use is a document editor: when the user opens a second file from the file explorer, the operating system starts a new process. That process notices that the editor is already running, sends the file name to it, and exits. The running editor opens the file in a new tab.

What you can do with it

Principles

  • One instance per user. Two users of the same machine can each run their own instance. See How it works for the exact scope on each operating system.
  • Cross-platform. It works on Windows, Linux and macOS. The notification uses a named pipe, which is backed by a Unix domain socket on Linux and macOS.
  • Identified by a GUID. Every process of the application creates its SingleInstance with the same application id. Generate a new GUID once for your application and keep it in the code.

Namespace

The types are in the Meziantou.Framework namespace:

TypeContains
SingleInstanceDetects the first instance, starts the notification server and sends notifications
SingleInstanceEventArgsThe process id and the arguments of the instance that sent a notification

Next steps