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);
        }
Beispiel #2
0
 private void OnSecondInstanceStarted()
 {
     try
     {
         SecondInstanceStarted?.Invoke(this, EventArgs.Empty);
     }
     catch (Exception ex)
     {
         ApplicationEventSource.Log.FatalException(ex);
     }
 }
Beispiel #3
0
 protected virtual void OnSecondInstanceStarted(SecondInstanceEventArgs e)
 {
     Task.Run(() => SecondInstanceStarted?.Invoke(this, e));
 }
Beispiel #4
0
 private static void OnSecondInstanceStarted()
 {
     SecondInstanceStarted?.Invoke(null, EventArgs.Empty);
 }
Beispiel #5
0
 public bool SignalExternalCommandLineArgs(IList <string> args)
 {
     SecondInstanceStarted?.Invoke(null, EventArgs.Empty);
     return(true);
 }