/// <summary> /// This initilizes the UI and the pin clock. /// </summary> public ClientWindow() { InitializeComponent(); MessageBox.Document = new FlowDocument(); ping.Interval = 1000; ping.Elapsed += (o, e) => { try { connection.Send("ping"); } catch (Exception) { } }; ping.Enabled = false; }
public void Init() { new Thread(() => { InitCommands(); connection = new TCPHandler(Address, Port); connection.OnConnection += OnConnectionState; connection.OnMsg += OnMesseage; connection.OnBadThing += () => { System.Windows.MessageBox.Show("You have been Disconnected from the server.", "Connection Closed", MessageBoxButton.OK); //You'll notice these calls throughout the code, //when working with WPF, you are not allowed to update the UI directly from anything but //the UI thread. This ensures that the actions we want to take, are taken in the context //of the UI thread. IsConnected = false; try { Dispatcher.Invoke(new Action(() => { Close(); })); } catch (Exception) { //Since the window actually closes during this process, this will throw an exception (Cause it can't compleate) //So we catch it and do nothing with it. } }; connection.CreateSocket(false); new Thread(() => { while (!IsConnected) { Thread.Sleep(500); } connection.Send("connect " + ourNickname); ping.Enabled = true; ping.Start(); //connection.Send("join nick #root"); }).Start(); }).Start(); }