Question: I'm having 2 forms. From one form I created and shown the other form. It's working great. But when I try to close or Dispose that form from the form that created it I get following Exception:

```

Exception :
   Value Dispose() cannot be called while doing CreateHandle().

Stack Trace :
========================
   at System.Windows.Forms.Control.Dispose(Boolean disposing)
   at System.Windows.Forms.Label.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at System.Windows.Forms.Control.Dispose(Boolean disposing)
   at System.Windows.Forms.ContainerControl.Dispose(Boolean disposing)
   at System.Windows.Forms.Form.Dispose(Boolean disposing)
   at Speedometer_Application.frmSpeedometer.Dispose(Boolean disposing) 

```

Any idea????

Answer: 
The error `Value Close() cannot be called while doing CreateHandle()` usually happens when we try to close the form in the constructor or Load event.

For example, the following code gives the error:

```
private void frmCustomer_Load(object sender, EventArgs e)
{
 if (!Valid())
  this.Close;
}

```

The Solution:

```
private void frmCustomer_Load(object sender, EventArgs e)
{
 if (!Valid())
  this.BeginInvoke(new MethodInvoker(Close));
} 

```

You can use this in your code.
The code is as follows: 

```
if (frmMain.objfrm== null)
{   
     frmMain.objfrm = frmMyForm.Instance;     
     frmMain.objfrm.ShowInTaskbar = false;    
}
frmMain.objfrm.Show();
frmMain.objfrm.BringToFront();

```

frmMain is the Main Form that has a static variable of the frmMyForm. than in my code whereever i want to use this I just check if it's not null than create it using a static Instance and than give the peoperty.

While closing the form I have the following code:

```
frmMain.objfrm.Close_this();

```

The Close\_this calls the Close() or Dispose() method.

But when I call that function I get the above exception.