private void Application_Startup(object sender, StartupEventArgs e) { try { // set language Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN"); string root = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]); Environment.CurrentDirectory = root; pipe = new NamedPipeManager(Name); if (!pipe.SingleServer()) { if (e.Args.Length == 1) { pipe.Write(e.Args[0]); } Environment.Exit(0); } pipe.ReceiveString += pipe_ReceiveString; pipe.StartServer(); var win = new UserWindow(); win.Closed += win_Closed; win.Show(); } catch (Exception _e) { MessageBox.Show(_e.Message); Application.Current.Shutdown(); pipe.StopServer(); } }
public void NamedPipeManager() { string result = string.Empty; var manager = new NamedPipeManager("MarkdownMonster_Tests"); manager.ReceiveString += (s) => { Console.WriteLine("Received results: " + s); result += s + "\r\n"; }; manager.StartServer(); Thread.Sleep(200); // allow thread to spin up var manager2 = new NamedPipeManager("MarkdownMonster_Tests"); manager2.Write("Hello World"); manager2.Write("Goodbye World"); manager.StopServer(); Thread.Sleep(200); Assert.IsFalse(string.IsNullOrEmpty(result), "Result shouldn't be null"); }
public static void StartServer() { if (bUseSingleInstance) { NamedPipeManager PipeManager = new NamedPipeManager(AppPipeName); PipeManager.StartServer(); PipeManager.ReceiveString += HandleNamedPipe_OpenRequest; } }
private TangerineSingleInstanceKeeper(string[] args) { bool isOnlyInstance; mutex = new Mutex(true, MutexName, out isOnlyInstance); if (!isOnlyInstance) { if (args.Length > 0) { var stream = new MemoryStream(); TangerineYuzu.Instance.Value.WriteObject(string.Empty, stream, args, Serialization.Format.JSON); var serializedArgs = Encoding.UTF8.GetString(stream.ToArray()); var manager = new NamedPipeManager(PipeServerName); manager.Write(serializedArgs); } System.Environment.Exit(0); } pipeManager = new NamedPipeManager(PipeServerName); pipeManager.StartServer(); pipeManager.ReceiveString += OnAnotherInstanceArgsRecieved; }
public void CustomInitialize(frmChummerMain mainControl) { Log.Info("CustomInitialize for Plugin ChummerHub.Client entered."); MainForm = mainControl; if (String.IsNullOrEmpty(ChummerHub.Client.Properties.Settings.Default.TempDownloadPath)) { ChummerHub.Client.Properties.Settings.Default.TempDownloadPath = Path.GetTempPath(); } //check global mutex BlnHasDuplicate = false; try { BlnHasDuplicate = !Program.GlobalChummerMutex.WaitOne(0, false); } catch (AbandonedMutexException ex) { Log.Error(ex); Utils.BreakIfDebug(); BlnHasDuplicate = true; } if (PipeManager == null) { PipeManager = new NamedPipeManager("Chummer"); Log.Info("blnHasDuplicate = " + BlnHasDuplicate.ToString()); // If there is more than 1 instance running, do not let the application start a receiving server. if (BlnHasDuplicate) { Log.Info("More than one instance, not starting NamedPipe-Server..."); throw new ApplicationException("More than one instance is running."); } else { Log.Info("Only one instance, starting NamedPipe-Server..."); PipeManager.StartServer(); PipeManager.ReceiveString += HandleNamedPipe_OpenRequest; } } }
public MainWindow( MainWindowVM viewModel, IDialogService dialogService, IRuntimeDataService runtimeDataService) { _dialogService = dialogService; _runtimeDataService = runtimeDataService; InitializeComponent(); WindowChrome windowChrome = new WindowChrome() { CaptionHeight = 55, CornerRadius = new CornerRadius(0), GlassFrameThickness = new Thickness(0), NonClientFrameEdges = NonClientFrameEdges.None, ResizeBorderThickness = new Thickness(6), UseAeroCaptionButtons = false }; WindowChrome.SetWindowChrome(this, windowChrome); _namedPipeManager = new NamedPipeManager("TwitchLeecher"); _namedPipeManager.OnMessage += OnPipeMessage; _namedPipeManager.StartServer(); // Hold reference to FontAwesome library ImageAwesome.CreateImageSource(FontAwesomeIcon.Times, Brushes.Black); SizeChanged += (s, e) => { if (WindowState == WindowState.Normal) { WidthNormal = Width; HeightNormal = Height; } }; LocationChanged += (s, e) => { if (WindowState == WindowState.Normal) { TopNormal = Top; LeftNormal = Left; } }; Loaded += (s, e) => { HwndSource.FromHwnd(new WindowInteropHelper(this).Handle).AddHook(new HwndSourceHook(WindowProc)); DataContext = viewModel; if (viewModel != null) { viewModel.Loaded(); } LoadWindowState(); }; Activated += (s, e) => { if (viewModel != null && !_shown) { _shown = true; viewModel.Shown(); } }; Closed += (s, e) => { SaveWindowState(); _namedPipeManager.StopServer(); }; }