private void btnConnect_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; WcfClientHelper.FaultMessage = null; if (_loadingControl == null) { _loadingControl = new LoadingControl(); int loadingControlX = (this.Width / 2) - (_loadingControl.Width / 2); int loadingControlY = ((this.Height / 2) - (_loadingControl.Height / 2)) - 20; _loadingControl.Location = new Point(loadingControlX, loadingControlY); this.Controls.Add(_loadingControl); } _loadingControl.BringToFront(); _loadingControl.Visible = true; Task connectingTask = Task.Factory.StartNew <bool>(() => { ServiceRemotingCallback callback = new ServiceRemotingCallback(); WcfClientHelper.ConnectIpc(callback); ((ICommunicationObject)WcfClientHelper.PipeFactory).Closing += PipeFactory_Closing; ((ICommunicationObject)WcfClientHelper.PipeFactory).Faulted += PipeFactory_Faulted; return(WcfClientHelper.IsConnected); }).ContinueWith(x => { HandleConnectionResult(x.Result); }); }
private void MainForm_Load(object sender, EventArgs e) { this.ApplicationExiting = true; ServiceRemotingCallback.ClearAllEventHandlers(); ServiceRemotingCallback.ServerStoppingEvent += ServiceRemotingCallback_ServerStoppingEvent; ServiceRemotingCallback.EventToLogEvent += ServiceRemotingCallback_EventToLogEvent; ServiceRemotingCallback.PingEvent += ServiceRemotingCallback_PingEvent; ServiceRemotingCallback.TestConnectionCallbackEvent += ServiceRemotingCallback_TestConnectionCallbackEvent; ServiceRemotingCallback.TunnelStatusChangedEvent += ServiceRemotingCallback_TunnelStatusChangedEvent; ServiceRemotingCallback.PlinkTextOutputEvent += ServiceRemotingCallback_PlinkTextOutputEvent; ServiceRemotingCallback.SaveSettingsCallbackEvent += ServiceRemotingCallback_SaveSettingsCallbackEvent; AppendLog("Client", "UI started - connected to Windows Service"); _currentSettings = WcfClientHelper.RemotingObject.GetSettings(); _currentSettings.IsDirty = false; bindingSource1.DataSource = _currentSettings; AppendLog("Client", "Windows Service settings retrieved and bound"); WcfClientHelper.RemotingObject.RegisterCallbackClient(); _pingTimer = new System.Timers.Timer(Constants.ClientPingInterval * 1000); _pingTimer.Elapsed += pingTimer_Elapsed; _pingTimer.AutoReset = true; _pingTimer.Start(); }