Solved

Error when creating window handle in Winforms MDI App

Posted on 2009-07-13
3
721 Views
Last Modified: 2013-12-17
I have written a Windows Forms MDI Application. In this application the user is allowed to create new windows without any restriction. At some point, after creating several hundreds of windows, the following error occurs:

System.ComponentModel.Win32Exception: Fehler beim Erstellen des Fensterhandles.
   bei System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   bei System.Windows.Forms.Control.CreateHandle()
   bei System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   bei System.Windows.Forms.Control.CreateControl()
   bei System.Windows.Forms.Control.ControlCollection.Add(Control value)

How can I test, if the next window to create can be created successfully or not?
Or how can I test, if the program has reached 90% of the maximum handles, so that I can stop creating new windows early enough to ensure, the rest of the programm will go on working correctly, because if I will stop one window before the maximum the program possibly will need more handles without creating new windows and the error will occur later without creating any new window.
So the best would be to test, if the program has reached x% of the maximum handles. Does someone know how to do this or does someone has any other suggestion to solve my problem?
 
Thanks for any help.
0
Comment
Question by:thbruns
  • 3
3 Comments
 

Author Comment

by:thbruns
ID: 24839380
Perhaps I should add some information here:

A fix mamimum number of windows, the user can create, is no solution, because the application has different types of windows. Some of them have many child controls others only have a few.
0
 

Author Comment

by:thbruns
ID: 24839417
... and I assume the number of available handles differ for some operating systems.

So I need to know how many window handles does my application use at the moment and how many window handles can my application use at maximum.
0
 

Accepted Solution

by:
thbruns earned 0 total points
ID: 24861122
I have found the solution to get the number of user objects and gdi object per process. See:
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c73c.aspx
(see section 40.8 on that page)

To get the current used handles use the following code:
System.Diagnostics.Process.GetCurrentProcess().Handle
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 46
Closing all open child forms. 4 38
vb.net - How to check if current user is an administrator? 6 34
Connection String 16 41
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now