Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Error Creating Window Handle

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joel Rumerman - 10 Sep 2004 02:42 GMT
I have an application that does the following in one of its user controls:

It creates a grid of panels (9x9) and then in each of those panels it places
a label (9x9) labels. There are other controls on the page and so I think
the total number of controls is 200. (81+81 + 35 or so.) Randomly, I'm
getting Error Creating Window Handle errors.

This user control gets built and rebuilt as the user navigates a the browser
control on the right. They may be looking at 15+ user controls in a span of
45 seconds.

Few Questions:
   a. Could it be because I have too many controls on the page and they are
not getting destroyed properly?
   b. If I open up Task Manger and add Handles to the Columns is this a
good indicator of the resources my application is using?
   c. How else can I fix this problem.

The application uses all managed resources. It's running 1.1 and is
programmed in VB.NET. The machine is Windows XP Pro with 512Mb RAM.

Thx, Joel
Joel Rumerman - 10 Sep 2004 02:52 GMT
So I played around with Task Manager adding Handles, User OBject, and GDI
Objects to the columns collection and lo-and-behold, when User Objects
reached 10000, BOOM! The program crashed. So, I looked into my code, wrote
some cleanup code, handled the destruction of objects in the dispose method
myself and wham ... User Objects never gets above 175, and it no longer
crashes.

Stupid me, I was re-creating the user control, but not disposing of the
previous labels and panels.

So, for all you folks who have had trouble with Window Handles, it may not
be the window handles, but the User Objects counter that's important. If you
keep creating objects on a form without destroying the previous one due to
some input or from the user or something else... you'll probably having the
same problem.

-Joel

> I have an application that does the following in one of its user controls:
>
[quoted text clipped - 18 lines]
>
> Thx, Joel
Jeffrey Tan - 12 Sep 2004 14:29 GMT
Hi Joel,

I am very glad your problem resolved :-).

In .Net, there are 2 types of resource freeing: managed objects and
unmanaged resources. All .Net class instances are managed resource, CLR will
add reference counters on these objects, once one instance's reference count
drops to 0, it will be implicitly collected by GC. For unmanaged resources,
they are not .Net's type, but the resource of Windows, such as windows
handle, database connections, bitmap memory, etc. .Net will not manage
resource counter for them, .Net use IntPtr pointer to marshal them, .Net has
nothing knowledge of them and we should handle the resource free of them
ourselves. Implicitly, GC will invoke finalize method before collect the
managed resource, finalize method will free the unmanged sources. But when
unmanaged resource is rarity, such as the memory is not large for bitmap, or
our application uses too much Win32 resouces, there should be a way to
explicitly free the unmanaged resource, this explicit way is Dispose method.

A USER object is an object from Window Manager, which includes windows,
menus, cursors, icons, hooks, accelerators, monitors, keyboard layouts, and
other internal objects. They are unmanaged resources. We should override the
Dispose method of our customized control or class and freeing all the
unmanaged resources in this method.

Hope this makes sense to you. Have a good weekend!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.