public void Server(TMain main) { do { try { using (NamedPipeServerStream pipeServer = new NamedPipeServerStream("CheckRunApp", PipeDirection.Out)) { pipeServer.WaitForConnection(); try { System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { main.Show(); })); } // Catch the IOException that is raised if the pipe is broken // or disconnected. catch (IOException e) { } } } catch (Exception ex) { if (ex.HResult == -2147024665) { Thread.Sleep(1000); } continue; } } while (true); }