using System.Windows; namespace EonaCat.PortMonitor { /// /// Interaction logic for ConnectionDetailsWindow.xaml /// public partial class ConnectionDetailsWindow : Window { public ConnectionDetailsWindow(ConnectionInfo conn) { InitializeComponent(); ProtocolText.Text = conn.Protocol; LocalAddressText.Text = conn.LocalAddress; LocalPortText.Text = conn.LocalPort.ToString(); RemoteAddressText.Text = conn.RemoteAddress; RemotePortText.Text = conn.RemotePort.ToString(); StateText.Text = conn.State; // Update the state text every second System.Windows.Threading.DispatcherTimer stateTimer = new System.Windows.Threading.DispatcherTimer(); stateTimer.Interval = TimeSpan.FromSeconds(1); stateTimer.Tick += (sender, e) => UpdateStateText(conn); stateTimer.Start(); ProcessIdText.Text = Convert.ToString(conn.ProcessId); ProcessNameText.Text = conn.ProcessName; ConnectionDurationText.Text = Convert.ToString(conn.FormattedConnectionDuration); // Update the connection duration text every second System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(1); timer.Tick += (sender, e) => UpdateConnectionDurationText(conn); timer.Start(); } private void UpdateStateText(ConnectionInfo conn) { Dispatcher.Invoke(() => StateText.Text = conn.State); } private void UpdateConnectionDurationText(ConnectionInfo conn) { Dispatcher.Invoke(() => ConnectionDurationText.Text = Convert.ToString(conn.FormattedConnectionDuration)); } } }