Error creating window handle

J

Jonathan Boivin

Hi people,

Let me introduce to how I get this error.

I have a form which load all my bills representation depending upon filters
which each bill is a usercontrol of my own having some textboxes containing
bill's datas. (I already replaced the labels by painting the text instead.)

When I click on my filter button, it clears the current usercontrol bills
and load the new ones upon the current chosen filters. The bug happens when
you filter multiple times which doesn't depend on the filters chosen. There
is not precise time when the bug is thrown. My bill usercontrol includes
also two other usercontrols which show the history of the bill and one other
which show furthermore infos. The futhermore infos usercontrol only contains
textboxes and labels (again) had been replaced by text screen printing. The
history controls are a ComboBox I created myself from a ListBox I created
myself from skratch. The ComboBox includes 1 Label, 1 Button and My List
Control. This last one only has a panel control and inherits from
UserControl and it's already disposing all drawing objects (not quite sure
though the disposing is linked to the problem).

From what I see, I think the problem is coming from a number of exceeding
window handle created. (Because when I look into my last created bill
usercontrol, not all the controls within are created). Further, when the bug
just happened (after storing to a log file), I can't open anything else
(external programs I mean) unless I close my own program.

How come can I reach the window handles limit if the first time I load all
bills it doesn't bug, only after a few tries ?

Also, is there a way to know how many window handles are created ?

Thanks,
Jonathan Boivin
 
R

rowe_newsgroups

Also, is there a way to know how many window handles are created ?

What OS are you using? If I'm not mistaken, Windows XP allows 10,000
window handles per process - and I doubt you have that many. I'm
curious though, are you sure you are actually destroying the window
handles when "it clears the current usercontrol bills"? Perhaps you
could use the DestroyWindow API to make sure you are killing the
handles?

http://msdn2.microsoft.com/en-us/library/ms632682.aspx
http://www.pinvoke.net/default.aspx/user32/DestroyWindow.html ).

Also, to get a count of window handles you could use the
EnumChildWindows API

http://msdn2.microsoft.com/en-us/library/ms633494.aspx
http://www.pinvoke.net/default.aspx/user32/EnumChildWindows.html

Thanks,

Seth Rowe
 
J

Jonathan Boivin

I am running under WinXP and I just get aware of this 10,000 window handles
not so long ago.

I just added this file to my project and use the EnumWindows class to count
how many handles I have.
The file used is located at (got to copy/paste) :
http://www.vbaccelerator.com/home/n...terprocessCommunicationsVB_EnumWindows_vb.asp

I create a function using the EnumWindows class to count the handles which
is :
Public Shared Function CountWindowHandles() As Integer
Dim i As Integer
Dim eW As New vbAccelerator.Components.Win32.EnumWindows
eW.GetWindows()
For i = 0 To eW.Items.Count - 1
Try
If eW.Items(i).Text.ToUpper.StartsWith("CLINICA") Then
Dim MyPointer As IntPtr = eW.Items(i).Handle
Dim handlesCount As New
vbAccelerator.Components.Win32.EnumWindows
handlesCount.GetWindows(MyPointer)
If handlesCount.Items.Count > 0 Then
Return handlesCount.Items.Count
End If
End If
Catch
End Try
Next

Return 0
End Function

This works fine and I add two MsgBox to display me the number of handles
before clearing the bill usercontrols and one after.
First time = 53, 53.
Second time = 2608, 53 (Filtering is set to ALL)

The bill usercontrols are added in a Panel which automanage the vertical
scrollbar. I use the Clear method on the Items of the panel to remove them.
53 represents when my software and the window (without bills) are opened and
2608 is including the bills.

I downloaded the C# software version which enumerates the handles
(http://www.vbaccelerator.com/home/N...dows/Enumerating_Windows/EnumWindows_Code.asp).
When I browse throught my software primary handle I see a lot of :
HANDLE NUMBER + WindowsForms10.STATIC.app.0.33c0d9d
or
HANDLE NUMBER + WindowsForms10.EDIT.app.0.33c0d9d

I made a screen shot of what I mostly see which is avaible at :
http://www.cints.net/WHD-ScreenShot.JPG


I decided to make another test, but this time not with the billing window. I
opened 10 client accounts which was representing around 1000 handles. I
closed them and loaded them more than 10 times, no bug. When I'm using the
billing window, even if I close it after the filtering and reopen and
refilter, the third time (or so) it craches.

Thanks,
Jonathan Boivin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top