Inheritance: global::System.IDisposable
        private readonly int pingRefreshRate = 2;   // seconds

        public AddAppDialog()
        {
            InitializeComponent();

            listener = new DiscoveryClientAdapter();
            listener.DiscoveredEvent += OnSystemDiscovered;
            listener.LostEvent += OnSystemLost;

            discoveryClient = DiscoveryClient.Create();
            discoveryClient.AddListener(listener);
            discoveryClient.Ping();
            
            updateTimer = new DispatcherTimer();
            updateTimer.Tick += UpdateDiscoveredApps;
            updateTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000 / 30); // 30 updates per second
            updateTimer.Start();

            refreshTimer = new DispatcherTimer();
            refreshTimer.Tick += RefreshPing;
            refreshTimer.Interval = new TimeSpan(0, 0, 0, pingRefreshRate, 0);
            refreshTimer.Start();
        }
        protected override void OnClosed(EventArgs e)
        {
            updateTimer.Stop();
            refreshTimer.Stop();

            discoveryClient.RemoveListener(listener);

            discoveryClient.Dispose();
            discoveryClient = null;
        }