Esempio n. 1
0
 /// <summary>
 /// Initial refresh has completed.
 /// </summary>
 private void RefreshCompleted()
 {
     refreshBusy             = false;
     refreshProgress.Visible = false;
     UpdateNoDevicesItem();
     CanRefreshDevicesChanged.Fire(this);
 }
Esempio n. 2
0
        /// <summary>
        /// Refresh the device list and restart the device monitor
        /// </summary>
        public void RefreshDevices(bool startMonitorAnyWay = false)
        {
            if (refreshBusy)
            {
                return;
            }

            refreshBusy = true;
            CanRefreshDevicesChanged.Fire(this);

            var monitorStarted = deviceMonitor.Enabled;

            deviceMonitor.Enabled = false;
            tvList.Items.Clear();
            ReloadList();
            deviceMonitor.Enabled = monitorStarted || startMonitorAnyWay;

            var ui = TaskScheduler.FromCurrentSynchronizationContext();
            var cs = ClientSize;

            refreshProgress.SetBounds((cs.Width - refreshProgress.Width) / 2, (cs.Height - refreshProgress.Height) / 2, refreshProgress.Width, refreshProgress.Height);
            refreshProgress.Visible = true;
            Task.Factory.StartNew(() => {
                // Thread.Sleep(1000);

                /*/
                 * deviceMonitor.WaitForInitialUpdate();
                 * /*/
                while (!deviceMonitor.ReceivedInitialUpdate())
                {
                    try
                    {
                        refreshProgress.Invoke((AnimationDelegate) delegate()
                        {
                            if (refreshProgress.Value >= refreshProgress.Maximum)
                            {
                                refreshProgress.Value = refreshProgress.Minimum;
                            }
                            else
                            {
                                refreshProgress.PerformStep();
                            }
                        });
                    }
                    catch (ObjectDisposedException)
                    {
                        // Object could be dispose in other thread if the form is closed.
                        // In that case we stop here.
                        break;
                    }
                }
                //*/
            }).ContinueWith(t => RefreshCompleted(), ui);
        }