/// <summary> /// The connect. /// </summary> public void Connect() { string port = this.userSettingService.GetUserSetting<string>(UserSettingConstants.ServerPort); if (backgroundProcess == null) { ProcessStartInfo processStartInfo = new ProcessStartInfo( "HandBrake.Server.exe", port) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, }; backgroundProcess = new Process { StartInfo = processStartInfo }; backgroundProcess.Start(); } // When the process writes out a line, it's pipe server is ready and can be contacted for // work. Reading line blocks until this happens. backgroundProcess.StandardOutput.ReadLine(); ThreadPool.QueueUserWorkItem(delegate { try { pipeFactory = new DuplexChannelFactory<IServerService>( new InstanceContext(this), new NetTcpBinding(), new EndpointAddress(string.Format("net.tcp://127.0.0.1:{0}/IHbService", port))); // Connect and Subscribe to the Server Service = pipeFactory.CreateChannel(); Service.Subscribe(); IsConnected = true; } catch (Exception exc) { Caliburn.Micro.Execute.OnUIThread(() => this.errorService.ShowError("Unable to connect to background worker service", "Please restart HandBrake", exc)); } }); }