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.
it is hard to say what is the problem from the code you posted.

The code that you posted should work (form shown with Show() should be possible to close with Dispose() method).

The reason why it does not work is probably somewhere in the form that you are trying to dispose of. When you call Dispose() method (according to the error message this is what happens) on an object, that object will try to dispose of all its children and do some cleanup. That is the place to look for error.

My suggestion is to comment out all your code in the form objfrm (or make new EMPTY form) and see if error happens. It should not happen. Then start adding commented code and see when the error happens. I bet it will be in the code that is being called as consequence of Dispose method.