Error Creating Window Handle In C#.net
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “Error Creating Window Handle” up vote 16 down vote favorite 3 We're working on a very large .NET WinForms composite application - not CAB, but a similar home grown framework. We're running in a Citrix and RDP environment running on Windows Server 2003. We're starting to run into random and difficult to reproduct "Error creating window handle" error that seems to be an old fashion handle leak in our application. We're making heavy use of 3rd Party controls (Janus GridEX, Infralution VirtualTree, and .NET Magic docking) and we do a lot of dynamic loading and rendering of content based on metadata in our database. There's a lot of info on Google about this error, but not a lot of solid guidance about how to avoid issues in this area. Does the stackoverflow community have any good guidance for me for building handle-friendly winforms apps? .net winforms handles share|improve this question edited Feb 27 '13 at 8:15 Kiquenet 5,0672486148 asked Sep 18 '08 at 0:26 user8133 141125 See also [this post of mine about "Error creating window handle"][1] and how it relates to USER Objects and the Desktop Heap. I provide some solutions. [1]: weblogs.asp.net/fmarguerie/archive/2009/08/07/… –Fabrice Aug 8 '09 at 0:41 add a comment| 5 Answers 5 active oldest votes up vote 21 down vote I have tracked down a lot of issues with UIs not unloading as expected in WinForms. Here are some general hints: alot
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up What to do about “Error creating window handle” errors in a C# application? up vote 3 http://stackoverflow.com/questions/88904/error-creating-window-handle down vote favorite 2 I've already looked at this question, and I've already checked out the suggestions that were made there. My program creates and destroys a lot of UI controls (a lot of UI controls), and anything that makes controls hang around after they're "destroyed" will cause this problem. (Fun fact: if you don't set a ToolStrip control's Visible property to false before you destroy its container, it doesn't get http://stackoverflow.com/questions/522534/what-to-do-about-error-creating-window-handle-errors-in-a-c-sharp-application disposed, because it's still registered with Windows to receive theme-change events; it only unregisters itself when it's not visible, and it apparently doesn't have any way of knowing that this is happening when its container is being destroyed.) The thing is, it's actually possible that my application really is running out of window handles. The program's got a single form that has nested tab controls. Each parent tab has 12 or 13 child tabs, and a child tab can have 30 or 40 controls on it. It's quite possible for the user to have 15 parent tabs open at any given time, and that's getting into the territory of 5000+ live controls in the application. And I know that many of my controls use more than one window handle. (And before you say "well, it looks like you've designed the UI wrong," let me disabuse of that: the whole reason the application exists in the first place is that the users have an enormous space of data that they need to be able to navigate to quickly. The tabs-within-tabs thing actually works really well for them.) My understanding is that there's a hard limit of 10,000 window handles per application. If that's actually true (I understand a lot of things to
application When building controls dynamically which compose of sub-controls you can sometimes run into http://challadotnetfaq.blogspot.com/2013/01/error-creating-window-handle-win32.html an problem where windows throws a "Error creating window handle" https://social.msdn.microsoft.com/Forums/windows/en-US/558001e5-f489-4d43-b595-71339ba204a4/what-can-cause-error-creating-window-handle-on-controlcreatehandle?forum=winforms error. The following registry key shows how many ‘USER Objects' handles are available on the system per process, creating any more ‘USER Objects' window handles will generate a "Error creating window handle" error. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\USERProcessHandleQuota On my machine the error creating value is 10000, and the following code creates the issue: [TestMethod] public void GenerateUserObjectsError() { UserControl ctrl = new UserControl(); ctrl.CreateControl(); for( int i = 0; i < 10001; i++ ) { ctrl.Controls.Add( new TextBox() ); } } You can use Task Manager to watch the number of ‘USER Objects' error creating window created for a process: The ‘USER Objects' column can be turned on via the View menu. Solution 1 Interestingly enough the "Error creating window handle" can be solved in this case by assigning the control to a Form before adding the sub-controls. [TestMethod] public void DoesNotFail() { UserControl ctrl = new UserControl(); ctrl.CreateControl(); Form frm = new Form(); frm.Controls.Add( ctrl ); for( int i = 0; i < 10001; i++ ) { ctrl.Controls.Add( new TextBox() ); } } After the control has been added to the Form, creating and adding sub-controls no longer consumes ‘USER Objects'. Solution 2 Clear the memory of Form/Panel Child controls using Control.Dispose() like below //clearing the objects(controls) memory of tableLayoutPanelTemplate controls and child controls TableLayoutControlCollection layoutCollection = tableLayoutPanelTemplate.Controls; for (int j = 0; j < layoutCollection.Count ; j++){ foreach (Control childControls in layoutCollection[j].Controls) { foreach (Control lowlevelControls in childControls.Controls) { childContro
Studio 2015 products Visual Studio Team Services Visual Studio Code Visual Studio Dev Essentials Office Office Word/Excel/PowerPoint Microsoft Graph Outlook OneDrive/Sharepoint Skype Services Store Cortana Bing Application Insights Languages & platforms Xamarin ASP.NET C++ TypeScript .NET - VB, C#, F# Server Windows Server SQL Server BizTalk Server SharePoint Dynamics Programs & communities Students Startups Forums MSDN Subscriber downloads Sign in Search Microsoft Search Windows Dev Center Windows Dev Center Explore What’s new for Windows 10 Intro to Universal Windows Platform Coding challenges Develop for accessibility Build for enterprise Windows Store opportunities Docs Windows apps Get started Design and UI Develop API reference Publish Monetize Promote Games Get started UI design Develop Publish Desktop Get started Design Develop API reference Test and deploy Compatibility Windows IoT Microsoft Edge Windows Holographic Downloads Samples Support Why Windows Dashboard Explore What’s new for Windows 10 Intro to Universal Windows Platform Coding challenges Develop for accessibility Build for enterprise Windows Store opportunities Docs Windows apps Get started Design and UI Develop API reference Publish Monetize Promote Games Get started UI design Develop Publish Desktop Get started Design Develop API reference Test and deploy Compatibility Windows IoT Microsoft Edge Windows Holographic Downloads Samples Support Why Windows Dashboard Ask a question Quick access Forums home Browse forums users FAQ Search related threads Remove From My Forums Answered by: What can cause "Error Creating Window Handle" on Control.CreateHandle()? Windows Forms > Windows Forms General Question 0 Sign in to vote What can cause an exception stating "Error Creating Window Handle"? I get this exception all the time: System.ComponentModel.Win32Exception: Error creating window handle. at System.Windows.Forms.NativeWindow.CreateH