Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            /*
             * var histogrammForm = new ThreadSamplingHistogramForm();
             * histogrammForm.SeriesColor = Color.Wheat;
             * histogrammForm.ThreadWrapper = new ThreadWrapperTest();
             * histogrammForm.Show(this);
             * return;
             */
            int count;

            if (sender == btnFill)
            {
                count = Environment.ProcessorCount;
            }
            else
            {
                count = 1;
            }
            IList <ThreadWrapper> newWrappers = ThreadsManager.AddThreads(count);

            flowLayoutPanel.Parent.SuspendLayout();
            flowLayoutPanel.SuspendLayout();
            try
            {
                foreach (var threadWrapper in newWrappers)
                {
                    ThreadControl threadControl = new ThreadControl();
                    threadControl.Wrapper      = threadWrapper;
                    threadControl.MinimumSize  = new Size(flowLayoutPanel.ClientRectangle.Width - 2, 0);
                    threadControl.Anchor       = AnchorStyles.Left | AnchorStyles.Right;
                    threadControl.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    threadControl.Margin       = new Padding(0);
                    flowLayoutPanel.Controls.Add(threadControl);

                    var seriesColor = AddSeries(threadWrapper);
                    threadControl.SeriesColor = seriesColor;

                    var preferredSize = threadControl.PreferredSize;
                    threadControl.Size = new Size(preferredSize.Width - 2, preferredSize.Height);

                    threadControl.Visible = true;
                }
            }
            finally
            {
                flowLayoutPanel.Parent.ResumeLayout(false);
                flowLayoutPanel.ResumeLayout();
            }
        }
Exemplo n.º 2
0
        private void UpdateAfinnity()
        {
            if (m_refreshAfinnityInprogress)
            {
                return;
            }

            m_refreshAfinnityInprogress = true;

            var cleared = false;

            this.SuspendLayout();
            var checkBoxes = flowPanelAfinnity.Controls.OfType <CheckBox>().ToArray();

            var count = m_processWrapper.ProcessAfinnityArray.Count;

            if (count != checkBoxes.Length)
            {
                flowPanelAfinnity.Controls.Clear();
                cleared = true;
            }
            flowPanelAfinnity.SuspendLayout();
            for (int index = 0; index < count; index++)
            {
                var checkBox = cleared ? new CheckBox() : checkBoxes[index];

                var flag = m_processWrapper.ProcessAfinnityArray[index];
                checkBox.Checked = flag;

                if (cleared)
                {
                    checkBox.AutoSize           = true;
                    checkBox.BackColor          = Color.Transparent;
                    checkBox.ForeColor          = Color.DarkGoldenrod;
                    checkBox.Text               = "CPU " + index;
                    checkBox.Tag                = index;
                    checkBox.CheckStateChanged += CheckBoxOnCheckStateChanged;
                    flowPanelAfinnity.Controls.Add(checkBox);
                    checkBox.Visible = true;
                }
            }
            flowPanelAfinnity.ResumeLayout(false);
            this.ResumeLayout();

            ThreadsManager.UpdateAfinnity(m_processWrapper.ProcessAfinnity);
            m_refreshAfinnityInprogress = false;
        }
Exemplo n.º 3
0
        public MainForm()
        {
            InitializeComponent();
            m_errorDisplayingManager = new ErrorDisplayingManager(lblLastError);
            btnFill.Text             = "Add " + Environment.ProcessorCount + " threads";

            m_processWrapper = new ProcessWrapper(NativeMethods.GetCurrentProcess());
            m_processWrapper.PropertyChanged += ProcessWrapperOnPropertyChanged;

            cmbProcessPriority.DataSource   = ProcessPriorityWrapper.AllValues;
            cmbProcessPriority.SelectedItem = m_previousProcessPriority = ProcessPriorityWrapper.IDLE_PRIORITY_CLASS;

            m_lastProcessPropsUpdateTime = DateTime.Now;

            NativeMethods.DisableProcessWindowsGhosting();
            ThreadsManager.Init();
            UpdateAfinnity();

            timer.Enabled = true;
        }
Exemplo n.º 4
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     ThreadsManager.FinishWork();
     ThreadsManager.StopAll();
 }
Exemplo n.º 5
0
 private void btnStop_Click(object sender, EventArgs e)
 {
     ThreadsManager.StopAll();
 }