-2

I am using VB2012 to create a WinForms application. The Form gives the user the ability to create "pages". Each page has a certain number of questions on it. The questions are survey questions with radio buttons for answers. Depending on how many questions are on a page, if they add too many pages, the program throws an error saying that it can not create the handle. Apparently I have too many open and need to dispose of some.

I need to determine if I am getting close to the limit or not so I can stop the creation of more pages, but I don't know what to check to see how close I am.

BTW, a page is simply a panel with another set of questions on it added to the main panel, so that the panels can be flipped through like pages.

Each question is a class with about 20 objects on it. The limit seems to be about 500 questions total (regardless of the number of pages).

Thanks.

John
  • 1,310
  • 3
  • 32
  • 58
  • 1
    Only create the controls for the viewable page, dispose of the rest. – LarsTech Jul 30 '15 at 18:20
  • I tried that, but it takes a few seconds (~5) to create the page and I want users to be able to flip through them quickly after they are created. Waiting for each page to create (after the first time) gets annoying. – John Jul 30 '15 at 18:24
  • Create one uber set and just change the properties such as text etc – Ňɏssa Pøngjǣrdenlarp Jul 30 '15 at 18:30
  • Without seeing your code, we have no idea what you are doing. 5 seconds is a *very* long time to render something, especially if we are talking about 20 objects. Show what you tried. – LarsTech Jul 30 '15 at 18:35
  • The code is extremely long. Too long to post here. Its not just 20 objects. Its 20 objects per question. And each page could have 100 questions or more. So we are talking about rendering 2000 objects (text boxes, radio buttons, panels, etc) each with its own event listeners and properties. That takes a few seconds. – John Jul 30 '15 at 18:43
  • As far as one Big set, that's what I tried, but swapping out the objects is what takes too much time. – John Jul 30 '15 at 18:44
  • I thought there was some kind of Process.GetHandles() code that I could use to simply grab the number. – John Jul 30 '15 at 18:45
  • 2
    The issue here is most likely in the way you have built your code, I'd suggest refactoring your current approach. Do you really need 2000 controls to show at once? – Saragis Jul 30 '15 at 18:50
  • @Saragis, yes, they need to see all the questions at one time. – John Jul 30 '15 at 19:12
  • If you are reaching even half way near the limit, understand that is a really really bad design. You should consider refactoring your code rather than trying to find a workaround to this. – Pradeep Kumar Jul 30 '15 at 19:17
  • no, *one* set of controls and swap out the *property values* as needed...no user can consume 2000 objects at once. – Ňɏssa Pøngjǣrdenlarp Jul 30 '15 at 19:36
  • Consider using a DataTable and DataGridView - assuming the controls for each question are a simple yes/no plus text or other simple repetitive pattern. – rheitzman Jul 30 '15 at 19:45
  • I'd still like to know the answer to the original question for future knowledge, but I'll try Plutonix idea for now and just create all the objects and swap out the questions and answers and see how that goes. – John Jul 30 '15 at 20:56

1 Answers1

1

I think the comments give some good advice to the OP, but just to answer the original question:

Process.GetCurrentProcess.HandleCount

Gets the number of handles opened by the process.

Handles provide a way for a process to refer to objects. A process can obtain handles to files, resources, message queues, and many other operating system objects. The operating system reclaims the memory associated with the process only when the handle count is zero.

Saragis
  • 1,782
  • 6
  • 21
  • 30