示例#1
0
        // TODO: fix Refresh() deadlock on closing gadget form when Windows is resuming
        /// <summary>
        /// Needs to be executed on the UI thread
        /// </summary>
        public static void Refresh()
        {
            if (!requestRefresh.Wait(0))
            {
                return;
            }
            //closing
            Global.TrayIcon.Icon = Properties.Resources.logo_nm_blue_ico;
            Global.TrayMenu.MenuItems[0].Enabled = false;
            Global.TrayMenu.MenuItems[1].Enabled = false;
            Global.TrayMenu.MenuItems[2].Enabled = false;
            Global.TrayMenu.MenuItems[3].Enabled = false;
            Global.TrayMenu.MenuItems[4].Enabled = false;
            Splash.StartupForm splashForm = new Splash.StartupForm();
            splashForm.UpdateStatus("Closing forms ...");
            for (int i = Application.OpenForms.Count - 1; i >= 0; i--)
            {
                if (!Application.OpenForms[i].InvokeRequired &&
                    !Application.OpenForms[i].Disposing &&
                    !Application.OpenForms[i].IsDisposed)
                {
                    string name = Application.OpenForms[i].Text;
                    splashForm.UpdateStatus("Closing " + name + " form ...");
                    Application.OpenForms[i].Close();
                }
            }
            splashForm.UpdateStatus("Stopping jobs ...");
            Jobs.TrafficMonitor.Stop();
            Jobs.CheckUpdates.Stop();

            //starting
            splashForm.UpdateStatus("Loading configuration file ...");
            Global.Load();
            Global.NetworkInterfaces = Lib.Network.NetworkInterface.GetAll(splashForm.UpdateStatus);
            splashForm.Stop();
            new Gadget.GadgetForm();
            new Thread(new ThreadStart(Jobs.TrafficMonitor.Start)).Start();
            new Thread(new ThreadStart(Jobs.CheckUpdates.Start)).Start();
            Global.TrayIcon.Icon = Properties.Resources.logo_nm_green_ico;
            Global.TrayMenu.MenuItems[0].Enabled = true;
            Global.TrayMenu.MenuItems[1].Enabled = true;
            Global.TrayMenu.MenuItems[2].Enabled = true;
            Global.TrayMenu.MenuItems[3].Enabled = true;
            Global.TrayMenu.MenuItems[4].Enabled = true;
            requestRefresh.Release();
        }
示例#2
0
        // TODO: fix Refresh() deadlock on closing gadget form when Windows is resuming
        /// <summary>
        /// Needs to be executed on the UI thread
        /// </summary>
        public static void Refresh()
        {
            if (!requestRefresh.Wait(0))
                return;
            //closing
            Global.TrayIcon.Icon = Properties.Resources.logo_nm_blue_ico;
            Global.TrayMenu.MenuItems[0].Enabled = false;
            Global.TrayMenu.MenuItems[1].Enabled = false;
            Global.TrayMenu.MenuItems[2].Enabled = false;
            Global.TrayMenu.MenuItems[3].Enabled = false;
            Global.TrayMenu.MenuItems[4].Enabled = false;
            Splash.StartupForm splashForm = new Splash.StartupForm();
            splashForm.UpdateStatus("Closing forms ...");
            for (int i = Application.OpenForms.Count - 1; i >= 0; i--)
                if (!Application.OpenForms[i].InvokeRequired &&
                    !Application.OpenForms[i].Disposing &&
                    !Application.OpenForms[i].IsDisposed)
                {
                    string name = Application.OpenForms[i].Text;
                    splashForm.UpdateStatus("Closing " + name + " form ...");
                    Application.OpenForms[i].Close();
                }
            splashForm.UpdateStatus("Stopping jobs ...");
            Jobs.TrafficMonitor.Stop();
            Jobs.CheckUpdates.Stop();

            //starting
            splashForm.UpdateStatus("Loading configuration file ...");
            Global.Load();
            Global.NetworkInterfaces = WinLib.Network.NetworkInterface.GetAll(splashForm.UpdateStatus);
            splashForm.Stop();
            new Gadget.GadgetForm();
            new Thread(new ThreadStart(Jobs.TrafficMonitor.Start)).Start();
            new Thread(new ThreadStart(Jobs.CheckUpdates.Start)).Start();
            Global.TrayIcon.Icon = Properties.Resources.logo_nm_green_ico;
            Global.TrayMenu.MenuItems[0].Enabled = true;
            Global.TrayMenu.MenuItems[1].Enabled = true;
            Global.TrayMenu.MenuItems[2].Enabled = true;
            Global.TrayMenu.MenuItems[3].Enabled = true;
            Global.TrayMenu.MenuItems[4].Enabled = true;
            requestRefresh.Release();
        }