Ejemplo n.º 1
0
        private void HandleProcessSelectorClosed(object sender, FormClosedEventArgs e)
        {
            ProcessSelector ps = sender as ProcessSelector;

            ps.FormClosed -= HandleProcessSelectorClosed;
            if (ps.SelectedPid != 0)
            {
                ProcessObserver po = new ProcessObserver(ps.SelectedPid, ps.SelectedProcessExecutable);
            }
            _processSelector = null;
        }
Ejemplo n.º 2
0
        private void BuildMenu()
        {
            _menu = new ContextMenu();

            _miExitMenu        = new MenuItem("Exit");
            _miExitMenu.Click += (o, e) =>
            {
                _internalExit = true;
                Application.Exit();
            };

            _miToggleShowHideMenu        = new MenuItem();
            _miToggleShowHideMenu.Click += (o, e) => ToggleWindowVisibility();

            MenuItem upd = new MenuItem("Update Interval");

            _miUpdInsane              = new MenuItem("1/4 second");
            _miUpdInsane.Click       += (o, e) => _timer.Interval = 250;
            _miUpdHalfSecond          = new MenuItem("1/2 second");
            _miUpdHalfSecond.Click   += (o, e) => _timer.Interval = 500;
            _miUpdOneSecond           = new MenuItem("1 second");
            _miUpdOneSecond.Click    += (o, e) => _timer.Interval = 1000;
            _miUpdTwoSeconds          = new MenuItem("2 second");
            _miUpdTwoSeconds.Click   += (o, e) => _timer.Interval = 2000;
            _miUpdThreeSeconds        = new MenuItem("3 second");
            _miUpdThreeSeconds.Click += (o, e) => _timer.Interval = 3000;

            _miToggleSingleCpuMenu        = new MenuItem();
            _miToggleSingleCpuMenu.Click += (o, e) =>
            {
                _totalCpuMode = !_totalCpuMode;
                UpdateVisualizationMode();
            };

            _miMachineInfo        = new MenuItem("Machine info");
            _miMachineInfo.Click += (o, e) =>
            {
                if (_machineInfo != null)
                {
                    _machineInfo.Close();
                    return;
                }

                _machineInfo              = new MachineInfo();
                _machineInfo.FormClosing += (o2, e2) =>
                {
                    _machineInfo = null;
                };
                _machineInfo.Show();
            };

            _selectProcess        = new MenuItem("Select process");
            _selectProcess.Click += (o, e) =>
            {
                if (_processSelector != null)
                {
                    return;
                }
                _processes.Update();
                _processSelector = new ProcessSelector();
                _processSelector.Initialize(_processes.Descriptors);
                _processSelector.Show();
                _processSelector.FormClosed += HandleProcessSelectorClosed;
            };

            upd.MenuItems.Add(_miUpdInsane);
            upd.MenuItems.Add(_miUpdHalfSecond);
            upd.MenuItems.Add(_miUpdOneSecond);
            upd.MenuItems.Add(_miUpdTwoSeconds);
            upd.MenuItems.Add(_miUpdThreeSeconds);

            _menu.MenuItems.Add(_miToggleShowHideMenu);
            _menu.MenuItems.Add(upd);
            _menu.MenuItems.Add(_miToggleSingleCpuMenu);
            _menu.MenuItems.Add(_selectProcess);
            _menu.MenuItems.Add(_miMachineInfo);
            _menu.MenuItems.Add(new MenuItem("-"));
            _menu.MenuItems.Add(_miExitMenu);

            _menu.Popup += (o, e) =>
            {
                _miToggleShowHideMenu.Text  = Visible ? "Hide CPU chart" : "Show CPU chart";
                _miToggleSingleCpuMenu.Text = _totalCpuMode ? "Show separate CPUs" : "Show Total CPU usage";
                _selectProcess.Enabled      = (_processSelector == null);
            };
            _trayIcon.ContextMenu = _menu;
        }