Wednesday, January 28, 2009

Error creating window handle

I faced this problem during a search screen. When I got the record in my GridView and click on a link I am opening a window form. The problem arise when I open 15 to 16 times the window.

Problem:The error is because windows has a limit of 1000 windows handles so I presume data grid returns more than 1000 or near enough rows. We need to reuse the same object rather than creating a new control every time.

Solution: To resolve this problem we have to open the task manager and add the columns Handles, Threads, User Objects, GDI Objects by clicking the View-> Select column. Now run your application and check which is increasing frequently once you complete the functionality. In my application I found the USER Objects increasing very quickly. I check my code and found that I was not disposing the objects and so its increasing. In my application I found that User Objects reach 10000 and it locks to load controls. So to resolve it I have set the objects to null and dispose the controls which were not required and when the window is going to close. It can possible that problem can arise from the Handlers. So at this time we have to detach all the event handlers when we close the window or we have to check is the handler is exist and if not exist then we have to create it else not. So this is one of the important article I faced it and really interested thats possible even .Net has Garbage Collection features. So we should remember that we don't require any control just dispose it. So keep in mind it because its very important.

You can add your comments and suggesions here. Do it yaar......

Vijay Modi

No comments:

Post a Comment