Why the application is working so slow when calling the two function in the timer2 tick event?
<p>I guess the problem is the too much foreach loops there are.
But i need them to get the sensor.Value</p>

<p>This is the two functions:</p>

<pre><code>private void cpuView()
        {

                Computer myComputer = new Computer();
                myComputer = new Computer(settings) { CPUEnabled = true };

                myComputer.Open();
                Trace.WriteLine("");
                foreach (var hardwareItem in myComputer.Hardware)
                {
                    if (hardwareItem.HardwareType == HardwareType.CPU)
                    {
                        hardwareItem.Update();
                        foreach (IHardware subHardware in hardwareItem.SubHardware)
                            subHardware.Update();

                        foreach (var sensor in hardwareItem.Sensors)
                        {
                            settings.SetValue("sensor", sensor.Value.ToString());
                            if (sensor.SensorType == SensorType.Temperature)
                            {
                                sensor.Hardware.Update();
                                settings.GetValue("sensor", sensor.Value.ToString());
                                temperature_label.Text = sensor.Value.ToString() + "c";//String.Format("{0} Temperature = {1}c", sensor.Name, sensor.Value.HasValue ? sensor.Value.Value.ToString() : "no value");
                            }
                        }
                    }
                }
        }
</code></pre>

<p>And the second function:</p>

<pre><code>private void gpuView()
        {


                Computer computer = new Computer();
                computer.Open();
                computer.GPUEnabled = true;

                foreach (var hardwareItem in computer.Hardware)
                {
                    if (videoCardType("ati", "nvidia") == true)
                    {
                        HardwareType htype = HardwareType.GpuNvidia;

                        if (hardwareItem.HardwareType == htype)
                        {

                            foreach (var sensor in hardwareItem.Sensors)
                            {

                                if (sensor.SensorType == SensorType.Temperature)
                                {

                                    sensor.Hardware.Update();
                                    if (sensor.Value.ToString().Length &gt; 0)
                                    {
                                        if (newGPULabel.Text.Length &lt; 1)
                                        {
                                            if (UpdatingLabel(sensor.Value.ToString(), string.Empty))
                                            {
                                                label8.Text = newGPULabel.Text;
                                            }
                                        }
                                        else if (UpdatingLabel(sensor.Value.ToString(), newGPULabel.Text.Substring(0, newGPULabel.Text.Length - 1)))
                                        {
                                            label8.Text = newGPULabel.Text;
                                        }
                                        newGPULabel.Text = sensor.Value.ToString() + "c";
                                        label8.Visible = true;
                                    }

                                    int t = newGPULabel.Text.Length;
                                    if (t &gt;= 4)
                                    {
                                        newGPULabel.Location = new Point(210, 100);

                                    }
                                    else
                                    {
                                        newGPULabel.Location = new Point(250, 100);
                                    }
                                    timer2.Interval = 1000;
                                    if (sensor.Value &gt; 90)
                                    {
                                        Logger.Write("The current temperature is ===&gt; " + sensor.Value);
                                        button1.Enabled = true;
                                    }
                                    this.Select();
                                }
                            }
                        }
                    }
                    else
                    {
                        HardwareType htype = HardwareType.GpuAti;

                        if (hardwareItem.HardwareType == htype)
                        {

                            foreach (var sensor in hardwareItem.Sensors)
                            {

                                if (sensor.SensorType == SensorType.Temperature)
                                {

                                    sensor.Hardware.Update();
                                    if (sensor.Value.ToString().Length &gt; 0)
                                    {
                                        if (newGPULabel.Text.Length &lt; 1)
                                        {
                                            if (UpdatingLabel(sensor.Value.ToString(), string.Empty))
                                            {
                                                label8.Text = newGPULabel.Text;
                                            }
                                        }
                                        else if (UpdatingLabel(sensor.Value.ToString(), newGPULabel.Text.Substring(0, newGPULabel.Text.Length - 1)))
                                        {
                                            label8.Text = newGPULabel.Text;
                                        }
                                        newGPULabel.Text = sensor.Value.ToString() + "c";
                                        label8.Visible = true;
                                    }

                                    int t = newGPULabel.Text.Length;
                                    if (t &gt;= 4)
                                    {
                                        newGPULabel.Location = new Point(210, 100);

                                    }
                                    else
                                    {
                                        newGPULabel.Location = new Point(250, 100);
                                    }
                                    timer2.Interval = 1000;
                                    if (sensor.Value &gt; 90)
                                    {
                                        Logger.Write("The current temperature is ===&gt; " + sensor.Value);
                                        button1.Enabled = true;
                                    }
                                    this.Select();
                                }
                            }
                        }
                    } 
            }
        }
</code></pre>

<p>And in the timer2 tick event:</p>

<pre><code>private void timer2_Tick(object sender, EventArgs e)
        {

            gpuView();
            cpuView();


        }
</code></pre>

<p>If i dont call this functions in the tick event the program is running smooth but even if im calling only one of the functions its stuck each n seconds.</p>

<p>The timer2 is set to interval 100 since im updating the cpu and gpu temperature i want to update them fast.
Im not sure if the problem is the too much foreach loops in the functions or that the interval is 100 so its trying to get the values from the sensors too fast so the hardware cant sned the information too fast.</p>

<p>Maybe there is a way to remove some of the foreach loops ?
I dont want to upload all my Form1 code to here . But all the snesors and hardware are connecting with the OpenHardwareMonitor.dll of the OpenHardwareMonitorApplication.</p>
