private static void StartServer(string name) { Task.Factory.StartNew(async() => { try { await using var pipe = new NamedPipeServerStream(name, PipeDirection.In, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous); while (true) { await pipe.WaitForConnectionAsync(_tokenSource.Token); using (var reader = new StreamReader(pipe, Encoding.UTF8, true, -1, true)) { var line = await reader.ReadToEndAsync(); var args = JsonConvert.DeserializeObject <string[]>(line); SecondInstanceStarted?.Invoke(null, new SingleInstanceEventArgs(args)); } pipe.Disconnect(); } } catch (TaskCanceledException) { Debug.WriteLine("Name Pipe Server was canceled."); } }, _tokenSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Current); }
private void OnSecondInstanceStarted() { try { SecondInstanceStarted?.Invoke(this, EventArgs.Empty); } catch (Exception ex) { ApplicationEventSource.Log.FatalException(ex); } }
protected virtual void OnSecondInstanceStarted(SecondInstanceEventArgs e) { Task.Run(() => SecondInstanceStarted?.Invoke(this, e)); }
private static void OnSecondInstanceStarted() { SecondInstanceStarted?.Invoke(null, EventArgs.Empty); }
public bool SignalExternalCommandLineArgs(IList <string> args) { SecondInstanceStarted?.Invoke(null, EventArgs.Empty); return(true); }