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. Need help! - accessing disposed object

Need help! - accessing disposed object

Scheduled Pinned Locked Moved C#
helptutorialquestion
3 Posts 2 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.
  • L Offline
    L Offline
    Libor Tinka
    wrote on last edited by
    #1

    When I dispose Control calling Control.Dispose() method, deactivate window and then re-activate window, I get ObjectDisposedException. Does anybody know how to avoid Windows.Forms creating handle of a disposed control?

    I 1 Reply Last reply
    0
    • L Libor Tinka

      When I dispose Control calling Control.Dispose() method, deactivate window and then re-activate window, I get ObjectDisposedException. Does anybody know how to avoid Windows.Forms creating handle of a disposed control?

      I Offline
      I Offline
      if_mel_yes_else_no
      wrote on last edited by
      #2

      If I'm reading this right. You have a form with a control, and then in your code you dispose of the control? So when you try to activate the window it throws the exception about the disposed object? That's because your form thinks it still exists when you go to re-activate the window. Before you dispose the object, you should remove it from the form with form.controls.remove(yourControl). Then you can dispose of the object all you want.

      L 1 Reply Last reply
      0
      • I if_mel_yes_else_no

        If I'm reading this right. You have a form with a control, and then in your code you dispose of the control? So when you try to activate the window it throws the exception about the disposed object? That's because your form thinks it still exists when you go to re-activate the window. Before you dispose the object, you should remove it from the form with form.controls.remove(yourControl). Then you can dispose of the object all you want.

        L Offline
        L Offline
        Libor Tinka
        wrote on last edited by
        #3

        When I use Controls.Remove(Control), the form start to working weird. It seems to be inactive (light blue) and blinking when clicked, but still keeping inactive. I also tried to use SuspendLayout() and ResumeLayout() methods. Nothing changed. And when all things worked (I had to remove more controls), Windows.Forms already tried to access correctly REMOVED and DISPOSED object calling its CreateHandle() method. The last thing I've done was to change design of my app. I have no more time to solve these bugs, maybe later. Thanks for answer!

        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