title: I just closed my application exited and got Win32Exception Error creating window handle what may do that?
body: <p>I read somewhere that i need to dispose objects when closing the application ?</p>
  
  <p>I have this properties i did to use them in tow functions i needed to invoke them since im using a backgroundworker.</p>
  
  <p>In most of the times when i closed my application it was ok but now i got this exception.</p>
  
  <pre><code>private string CpuTextLabelProperty
          {
              set
              {
                  if (InvokeRequired)
                  {
                      BeginInvoke(new Action(() =&gt; CpuTemperature_label.Text = value), null);
                  }
              }
              get
              {
                  return CpuTemperature_label.Text;
              }
  
          }
  
          private Point CpuLocationLabelProperty
          {
              set
              {
                  if (InvokeRequired)
                  {
                      BeginInvoke(new Action(() =&gt; CpuTemperature_label.Location = new Point(210, 200)), null);
                  }
              }
              get
              {
                  return CpuTemperature_label.Location;
              }
          }
  
          private string GpuTextLabelProperty
          {
              set
              {
                  if (InvokeRequired)
                  {
                      BeginInvoke(new Action(() =&gt; GpuTemperature_label.Text = value), null);
                  }
              }
              get
              {
                  return GpuTemperature_label.Text;
              }
  
          }
  
          private Point GpuLocationLabelProperty
          {
              set
              {
                  if (InvokeRequired)
                  {
                      BeginInvoke(new Action(() =&gt; GpuTemperature_label.Location= new Point(210,100)), null);
                  }
              }
              get
              {
                  return GpuTemperature_label.Location;
              }
  
          }
  
          private string Label4TextProperty
          {
              set
              {
                  if (InvokeRequired)
                  {
                      BeginInvoke(new Action(() =&gt; label4.Text = value), null);
                  }
              }
  
  
          }
  </code></pre>
  
  <p>The exception is on the property: GpuTextLabelProperty inside the get on the line:</p>
  
  <p>return GpuTemperature_label.Text;</p>
  
  <p>Win32Exception - Error creating window handle</p>
  
  <p>My Form1 closing event:</p>
  
  <pre><code>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(); }); 
              }
          }
  </code></pre>
  
  <p>If i need ot dispose something wich ones ? And how ?</p>
  
  <p>This is the functions im using the properties:</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());
                                  int t = CpuTextLabelProperty.Length;
                                  if (t &gt;= 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 &gt; 0)
                                      {
                                          if (GpuTextLabelProperty.Length &lt; 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 &gt;= 4)
                                      {
                                          GpuLocationLabelProperty = new Point(210, 100);
  
                                      }
                                      else
                                      {
                                          GpuLocationLabelProperty = 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 (GpuTextLabelProperty.Length &lt; 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 &gt;= 4)
                                      {
                                          GpuLocationLabelProperty = new Point(210, 100);
  
                                      }
                                      else
                                      {
                                          GpuLocationLabelProperty = 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 this is the full exception message:</p>
  
  <pre><code>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:
  </code></pre>