I have a problem with an application. The application have a Form contains a data grid view for displaying items data. There is a column within the data grid view of custom control type when pressing F3 on such column it shows another Form for searching the items. The other Form containing another data grid view with the property VirtualMode set to true and a NewRowNeeded event and a row count of 50. each time I scroll down 50 rows a SQL Query is executed and another 50 rows are added to the data grid view and so on. When I begin to fill in the main Form data grid view with items by searching for an item for each row using the item seach Form after a while on item adding I got the "cannot create a window handle" exception and when looking for the GDI objects they were 436 and the Handles were 2175 and I do not know how to solve such situation?

3 Years
Discussion Span
Last Post by cgeier

It sounds like you're not disposing of the old forms before you create new ones. You'll probably have to show the relevant code to see what is going wrong.

Edited by tinstaafl


Where did you get the information regarding number of handles from?

Edited by cgeier


Suzie999 no its not a third party app and its not my app meant I'm not the one who wrote it is already an existing app within the company where I'm working and I'm trying to fix the bugs issued by it.

cgeier You can know the number of User objects, GDI objects, Threads, and Handles beside many other things of all applications running in your PC through the Task Manager

Windows 7
1- Start Task Manager
2- Go to Processes tab
3- Select view (from the above menu list) then select the option "Select Columns"
4- Specify the columns you want to see

Windows 8 I do not remember steps exactly, but I think the steps may be the same as the steps with windows 7 try it, if not then try the below steps
1- Start Task Manager
2- Go to Users tab (if you see these columns there "ImageName, Username, CPU etx..." then you are in the right way)
3- Right-Click on any column header and a list will appear
4- Select the option "Select Columns"
5- Specify the columns you want to see

Sorry for replying from another user but the community nearly closed the above user

Edited by Amr_Mohammad_R


What OS is your computer using? Win7? What are the page file settings for your computer? You're going to probably have to post some of the code--the part that fires when you need to retrieve more rows and the part that retrieves the rows. Also some screen shots of what you are talking about may be useful.

Edited by cgeier


Just to clarify, you do have access to the source code of the app?

Seems like a lot of handles to be open really, I thought it was the garbage collector to deal with that if user does not dispose of objects themselves.

But I suppose there are cases where the garbage collector determines that an object is not finished with depending on the way it is coded.

Agree with a poster above, difficult to help without seeing code.

I's start with trawling through it and looking for objects which are not disposed.


It is important to either use "Using" statements and/or call the "Close" method for unmanaged code (such as COM objects). In short, if a "Close" method exists, use it.

Is this only occuring on one computer?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.