Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to destroy window handle

how to destroy window handle

Scheduled Pinned Locked Moved C#
questionhelptutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KaurGurpreet
    wrote on last edited by
    #1

    I have a user control (composed of 10 text boxes). on certain user inputs -> multiple rows of above user control are added to a form. After certain amount of operation, I start getting error - cannot create window handle. How do I need to clear window handle? Shouldn't it be automatically disposed?

    Gurpreet

    L L D 3 Replies Last reply
    0
    • K KaurGurpreet

      I have a user control (composed of 10 text boxes). on certain user inputs -> multiple rows of above user control are added to a form. After certain amount of operation, I start getting error - cannot create window handle. How do I need to clear window handle? Shouldn't it be automatically disposed?

      Gurpreet

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      accordance to google (some links), the problem comes only if you have too many loaded/visible usercontrol at the same time. for example, 1000 controls loaded at same time. try to reduce what you want to show. don't show all of them at once.

      K 1 Reply Last reply
      0
      • L Lost User

        accordance to google (some links), the problem comes only if you have too many loaded/visible usercontrol at the same time. for example, 1000 controls loaded at same time. try to reduce what you want to show. don't show all of them at once.

        K Offline
        K Offline
        KaurGurpreet
        wrote on last edited by
        #3

        I do not want to show them all at once. At a time say 100 are visible but after the user changes the input I need to show other 100. But how do a ensure that the handle is destroyed for previous ones?

        Gurpreet

        L 1 Reply Last reply
        0
        • K KaurGurpreet

          I do not want to show them all at once. At a time say 100 are visible but after the user changes the input I need to show other 100. But how do a ensure that the handle is destroyed for previous ones?

          Gurpreet

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          .NET do it perfectly using Dispose(). The old 100, remove it from Controls collection and dispose it. Then add another 100. Don't just Show/Hide or Visible=true/Visible=false, because it still in memory. Do dispose to remove it.

          1 Reply Last reply
          0
          • K KaurGurpreet

            I have a user control (composed of 10 text boxes). on certain user inputs -> multiple rows of above user control are added to a form. After certain amount of operation, I start getting error - cannot create window handle. How do I need to clear window handle? Shouldn't it be automatically disposed?

            Gurpreet

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            So you have 100 visible UserControls with 10 TextBoxes each, and a lot of invisible ones? That is a bad design. If you need that many user inputs, use a listing control, maybe a DataGridView. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

            1 Reply Last reply
            0
            • K KaurGurpreet

              I have a user control (composed of 10 text boxes). on certain user inputs -> multiple rows of above user control are added to a form. After certain amount of operation, I start getting error - cannot create window handle. How do I need to clear window handle? Shouldn't it be automatically disposed?

              Gurpreet

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              KaurGurpreet wrote:

              How do I need to clear window handle?

              You don't. That's handled by the controls themselves. If you're running into this problem, it could be that your Showing a form with ShowDialog (not Show!), but never Disposing it when you're done. Just because you can't see the form anymore doesn't mean it's gone. If you don't Dispose the form, you're leaking resources (handles). This issue does not come up if the form is shown with the Show method. If you're putting up hundreds and hundreds of controls, your design is the problem, not the window handles being released.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008
              But no longer in 2009...

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups