public bool RedirectToExistingInstance(Uri hyperlink) { IEnumerable <Process> processes = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Where(p => p.Id != Process.GetCurrentProcess().Id); if (processes.Count() > 0) { ChannelFactory <IHyperlinkService> factory = new ChannelFactory <IHyperlinkService>(new NetNamedPipeBinding()); try { foreach (Process proc in processes) { IHyperlinkService client = factory.CreateChannel(new EndpointAddress(string.Format("net.pipe://localhost/{0}/{1}", proc.Id, typeof(HyperlinkService).Name))); try { if (client.GetInstanceIdentifier() == GetInstanceIdentifier()) { return(client.ExecuteHyperlink(hyperlink)); } } catch (CommunicationException) { } catch (InvalidOperationException) { } catch (TimeoutException) { } } } finally { try { factory.Close(); } catch (InvalidOperationException) { } catch (CommunicationObjectFaultedException) { } catch (TimeoutException) { } finally { factory.Abort(); } } } return(false); }
private void MainWindowLoaded(object sender, RoutedEventArgs e) { try { _settingsService.ApplySettings(); } catch { } _loadedEvent.Set(); MainWindow mainWindow = System.Windows.Application.Current.MainWindow as MainWindow; if (mainWindow != null) { mainWindow.Loaded -= MainWindowLoaded; IHyperlinkService hyperlinkService = RootWorkItem.Services.Get <IHyperlinkService>(); hyperlinkService.Start(); hyperlinkService.ExecuteHyperlink(_userSessionService.ActivationUri); } }