private static void Main(string[] args) { if (Settings.Default.FrmMainAllowOnlyOneInstance && !MainForm.CreateNamedPipe(NAMED_PIPED_NAME)) { Logger.Info("Another instance of Logbert is already running."); // Bring the window of the other instance to front. NamedPipeClientStream anotherLogbertInstance = new NamedPipeClientStream( "." , NAMED_PIPED_NAME , PipeDirection.Out); try { if (!anotherLogbertInstance.ConnectAndWrite(Encoding.Default.GetBytes(BRING_TO_FRONT_MSG))) { Logger.Error("Unable to passing arguments to it."); return; } Logger.Info("Passing arguments to it and exiting."); if (args.Length > 0) { // Send the command line arguments to the other instance and exit. anotherLogbertInstance = new NamedPipeClientStream( "." , NAMED_PIPED_NAME , PipeDirection.Out); anotherLogbertInstance.ConnectAndWrite( Encoding.Default.GetBytes(args[0])); return; } } catch (Exception ex) { Logger.Error(ex.Message); return; } return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(args.Length == 0 ? string.Empty : args[0])); }