Hi , I have created a .net 2.0 windows application. This application creates form controls dynamically. Now when I am trying to run the application, it is throwing an exception "Error in creating windows handle". After this, application gets hang and nothing happens. At the first time, form gets displayed properly. On a particular event I am trying to reload the same form, while that time I am getting this exception. Anybody knows how to get rid of this. Any kind of help would be great full :)
A:
I struck an issue just like this recently.
There's a limit per process of just 10,000 handles - easy to reach if you're dynamically creating a complex UI.
To check if this is happening for you, use Task Manager - go to the Processes tab, turn on the columns for "USER Objects" and "GDI Objects". Then, reproduce the problem.
In my case, the USER Object count was hitting exactly 10,000 and then "boom".
If this is what's happening for you, you'll need to make sure that old controls are properly disposed before you create a new form. You might need to redesign to use less handles - this is what I needed to do.
Bevan
2009-12-02 07:37:15
Hi Bevan,Thanks for the reply. I checked my code and as you said all the controls were not getting disposed properly. I was throwing an exception for SplitterControl I am using on my form. And hence, it was breaking the flow. Now, what I am doing is, I am just collecting all the controls in a collection object and disposing each one of them forcefully.This works fine, but as form is disposed through its dispose() method, I am not sure if this is the optimal way of disposing controls.
Vijay Balkawade
2009-12-04 05:44:40
You need to ensure that you don't end up disposing the controls twice; I'd suggest using Reflector to check the code for `Control` to see if its `Dispose()` method prevents this by removing the control from the form.
Bevan
2009-12-04 07:23:35