none
List number of CPU Cores in ComboBox as Items RRS feed

  • Question

  • I am working on a Parallel download program and want to allow the user to select how many CPU cores they would like to use. I am using Environment.ProcessorCount to display in a label the number or Cores that the system has, but I can't figure  out how to get the number to list in a combobox as items - example: user has 8  cores -  the items should list from 1  to 8  ( 1,  2,...... 7, 8).

    How would I go about on making that happen?

    • Moved by CoolDadTx Monday, December 2, 2019 3:08 PM Winforms related
    Sunday, December 1, 2019 6:54 PM

Answers

  • Hi LaocheXe,

    Thank you for posting here.

    According to your description, you want to list number of CPU Cores in ComboBox as Items, and then the user can select how many CPU cores they would like to use.

    Here is a code example.

        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Button1_Click(object sender, EventArgs e)
            {
                int nums = Environment.ProcessorCount;
                for (int i = 1; i <= nums; i++)
                {
                    comboBox1.Items.Add(i);
                }
            }
    
            private void Button2_Click(object sender, EventArgs e)
            {
                int obj = (int)comboBox1.SelectedItem;
                MessageBox.Show(obj.ToString());
            }
        }
    

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by LaocheXe Monday, December 2, 2019 5:46 PM
    Monday, December 2, 2019 2:16 AM

All replies

  • Hi LaocheXe,

    Thank you for posting here.

    According to your description, you want to list number of CPU Cores in ComboBox as Items, and then the user can select how many CPU cores they would like to use.

    Here is a code example.

        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Button1_Click(object sender, EventArgs e)
            {
                int nums = Environment.ProcessorCount;
                for (int i = 1; i <= nums; i++)
                {
                    comboBox1.Items.Add(i);
                }
            }
    
            private void Button2_Click(object sender, EventArgs e)
            {
                int obj = (int)comboBox1.SelectedItem;
                MessageBox.Show(obj.ToString());
            }
        }
    

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by LaocheXe Monday, December 2, 2019 5:46 PM
    Monday, December 2, 2019 2:16 AM
  • Allow me to point out why this is not a useful thing to do.

    The bottleneck in your scenario is not CPU power.  The bottleneck is the network.  Your first download is going to suck up as much network bandwidth as your provider has available.  The second download will cause BOTH downloads to slow down to half-speed, because they're sharing the same network hose.  If you start 8 downloads, they will all go 1/8th as fast as one download would.

    What I'm saying is that, in general, if you have 8 files to download, it will take the same time whether you start them one after another or if you start them all at once.  You can't suck data faster than the hose can deliver.


    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Monday, December 2, 2019 8:01 AM
  • Unless of course the download speeds are not your max connection speed.


    George Frias - AWWshop, Wiki1978

    Monday, December 2, 2019 5:08 PM