Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8332597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:46:06+00:00 2026-06-09T02:46:06+00:00

I read somewhere that i need to dispose objects when closing the application ?

  • 0

I read somewhere that i need to dispose objects when closing the application ?

I have this properties i did to use them in tow functions i needed to invoke them since im using a backgroundworker.

In most of the times when i closed my application it was ok but now i got this exception.

private string CpuTextLabelProperty
        {
            set
            {
                if (InvokeRequired)
                {
                    BeginInvoke(new Action(() => CpuTemperature_label.Text = value), null);
                }
            }
            get
            {
                return CpuTemperature_label.Text;
            }

        }

        private Point CpuLocationLabelProperty
        {
            set
            {
                if (InvokeRequired)
                {
                    BeginInvoke(new Action(() => CpuTemperature_label.Location = new Point(210, 200)), null);
                }
            }
            get
            {
                return CpuTemperature_label.Location;
            }
        }

        private string GpuTextLabelProperty
        {
            set
            {
                if (InvokeRequired)
                {
                    BeginInvoke(new Action(() => GpuTemperature_label.Text = value), null);
                }
            }
            get
            {
                return GpuTemperature_label.Text;
            }

        }

        private Point GpuLocationLabelProperty
        {
            set
            {
                if (InvokeRequired)
                {
                    BeginInvoke(new Action(() => GpuTemperature_label.Location= new Point(210,100)), null);
                }
            }
            get
            {
                return GpuTemperature_label.Location;
            }

        }

        private string Label4TextProperty
        {
            set
            {
                if (InvokeRequired)
                {
                    BeginInvoke(new Action(() => label4.Text = value), null);
                }
            }


        }

The exception is on the property: GpuTextLabelProperty inside the get on the line:

return GpuTemperature_label.Text;

Win32Exception – Error creating window handle

My Form1 closing event:

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("Are you Sure you want to Exit. Click Yes to Confirm and No to continue", "WinForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                e.Cancel = true;
            }
            else
            {
                this.BeginInvoke((MethodInvoker)delegate { this.Close(); }); 
            }
        }

If i need ot dispose something wich ones ? And how ?

This is the functions im using the properties:

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());
                                int t = CpuTextLabelProperty.Length;
                                if (t >= 4)
                                {
                                    CpuLocationLabelProperty = new Point(210, 200); // not working to check everything about the locations \\

                                }
                                else
                                {
                                    CpuLocationLabelProperty = new Point(250, 200);
                                }
                                CpuTextLabelProperty = sensor.Value.ToString() + "c";//String.Format("{0} Temperature = {1}c", sensor.Name, sensor.Value.HasValue ? sensor.Value.Value.ToString() : "no value");
                                tempCpuValue = sensor.Value;
                                break;
                            }
                        }
                    }
                }
        }

        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 > 0)
                                    {
                                        if (GpuTextLabelProperty.Length < 1)
                                        {
                                            if (UpdatingLabel(sensor.Value.ToString(), string.Empty))
                                            {
                                               // Label8 = GpuText;
                                            }
                                        }
                                        else if (UpdatingLabel(sensor.Value.ToString(), GpuTextLabelProperty.Substring(0, GpuTextLabelProperty.Length - 1)))
                                        {
                                          //  Label8 = GpuText;
                                        }
                                        GpuTextLabelProperty = sensor.Value.ToString() + "c";
                                        tempGpuValue = sensor.Value;
                                        //label8.Visible = true;
                                    }

                                    int t = GpuTextLabelProperty.Length;
                                    if (t >= 4)
                                    {
                                        GpuLocationLabelProperty = new Point(210, 100);

                                    }
                                    else
                                    {
                                        GpuLocationLabelProperty = new Point(250, 100);
                                    }
                                   // timer2.Interval = 1000;
                                    if (sensor.Value > 90)
                                    {
                                        Logger.Write("The current temperature is ===> " + 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 > 0)
                                    {
                                        if (GpuTextLabelProperty.Length < 1)
                                        {
                                            if (UpdatingLabel(sensor.Value.ToString(), string.Empty))
                                            {
                                             //  Label8 = GpuText;
                                            }
                                        }
                                        else if (UpdatingLabel(sensor.Value.ToString(), GpuTextLabelProperty.Substring(0, GpuTextLabelProperty.Length - 1)))
                                        {
                                           // Label8 = GpuText;
                                        }
                                        GpuTextLabelProperty = sensor.Value.ToString() + "c";
                                        tempGpuValue = sensor.Value;
                                        //label8.Visible = true;
                                    }

                                    int t = GpuTextLabelProperty.Length;
                                    if (t >= 4)
                                    {
                                        GpuLocationLabelProperty = new Point(210, 100);

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

And this is the full exception message:

System.ComponentModel.Win32Exception was unhandled by user code
  Message=Error creating window handle.
  Source=System.Windows.Forms
  ErrorCode=-2147467259
  NativeErrorCode=87
  StackTrace:
       at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
       at System.Windows.Forms.Control.CreateHandle()
       at System.Windows.Forms.Control.get_Handle()
       at System.Windows.Forms.Control.get_WindowText()
       at System.Windows.Forms.Control.get_Text()
       at System.Windows.Forms.Label.get_Text()
       at HardwareMonitoring.Form1.get_GpuTextLabelProperty() in D:\C-Sharp\HardwareMonitoring\HardwareMonitoring\Hardwaremonitoring\Form1.cs:line 613
       at HardwareMonitoring.Form1.gpuView() in D:\C-Sharp\HardwareMonitoring\HardwareMonitoring\Hardwaremonitoring\Form1.cs:line 412
       at HardwareMonitoring.Form1.backgroundWorker1_DoWork(Object sender, DoWorkEventArgs e) in D:\C-Sharp\HardwareMonitoring\HardwareMonitoring\Hardwaremonitoring\Form1.cs:line 670
       at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
       at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
  InnerException:
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:46:07+00:00Added an answer on June 9, 2026 at 2:46 am

    You have to stop your background worker when you close or exit your application. The exceptions gets thrown at you because the objects your code is relying on are being torn down by the OS.

    See this thread on how to do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read somewhere that 99% of time you don't need to use a cursor.
I think I read somewhere that some modules only have object oriented interfaces (
I have this a and I don't know that I need to insert into
I read somewhere that one should never use error conditions as normal program flow.
I read somewhere that in order to use JTA and Tomcat (I'm also using
I have read somewhere that if class A is loaded by ClassLoaderA then all
I read somewhere that the ?: operator in C is slightly different in C++,
I read somewhere that Pattern Matching like that supported by the match/case feature in
I read somewhere that somebody could access a config value during run time but
I read somewhere that you would never run syncdb on a database, post its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.