/// <summary> /// Switch to the main running instance and optionally send data to the main instance. /// </summary> /// <param name="args">The command line arguments to pass.</param> public void SwitchTo(params string[] args) { var process = GetOtherInstance(); if (process == null) throw new InvalidOperationException("Can't switch to other instance. The current instance is the first instance."); // Get the main window and ensure it's running in foreground. var mainWindow = new Window(process.MainWindowHandle); if (mainWindow.IsMinimized) mainWindow.Show(ShowWindow.Restore); mainWindow.SetToForeground(); SendData(args, mainWindow.Handle); }