Error when creating window handle in Winforms MDI App
Posted on 2009-07-13
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.CreateControl(Boolean fIgnoreVisible)
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.