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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Urgent Help:Removing all EventHandlers

Urgent Help:Removing all EventHandlers

Scheduled Pinned Locked Moved C#
csharpperformancehelp
5 Posts 3 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.
  • S Offline
    S Offline
    Shubhabrata Mohanty
    wrote on last edited by
    #1

    Hi, I have a base Form and a base TextBox control. I have derived my Form and TextBox control from the base classes. In the base class of form, I am adding EventHandler for TextChanged Event of TextBox to do some generic operation like setting dirty flag. And again in the Derived View I am using TextChanged Event of TextBox Control to enable/disable the OK button. I am opening the form in Modal form. When I close the Form, it is not getting cleanup from memory. I checked it in .NET Profiler. In the profiler it is showing me that TextChanged EventHandler is still referring the Form. I want to cleanup all EventHandlers on Closed event of the Form. Pls let me know how I can cleanup all EventHandlers for all Controls in the Form. IT IS URGENT. Please let me know.

    D S 2 Replies Last reply
    0
    • S Shubhabrata Mohanty

      Hi, I have a base Form and a base TextBox control. I have derived my Form and TextBox control from the base classes. In the base class of form, I am adding EventHandler for TextChanged Event of TextBox to do some generic operation like setting dirty flag. And again in the Derived View I am using TextChanged Event of TextBox Control to enable/disable the OK button. I am opening the form in Modal form. When I close the Form, it is not getting cleanup from memory. I checked it in .NET Profiler. In the profiler it is showing me that TextChanged EventHandler is still referring the Form. I want to cleanup all EventHandlers on Closed event of the Form. Pls let me know how I can cleanup all EventHandlers for all Controls in the Form. IT IS URGENT. Please let me know.

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

      If you're showing the form by calling it's .ShowDialog() method, you MUST call .Dispose() on it when you're done with it. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        If you're showing the form by calling it's .ShowDialog() method, you MUST call .Dispose() on it when you're done with it. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        S Offline
        S Offline
        Shubhabrata Mohanty
        wrote on last edited by
        #3

        I am also calling .Dispose() after ShowDialog(). Still it is not helping...:(

        1 Reply Last reply
        0
        • S Shubhabrata Mohanty

          Hi, I have a base Form and a base TextBox control. I have derived my Form and TextBox control from the base classes. In the base class of form, I am adding EventHandler for TextChanged Event of TextBox to do some generic operation like setting dirty flag. And again in the Derived View I am using TextChanged Event of TextBox Control to enable/disable the OK button. I am opening the form in Modal form. When I close the Form, it is not getting cleanup from memory. I checked it in .NET Profiler. In the profiler it is showing me that TextChanged EventHandler is still referring the Form. I want to cleanup all EventHandlers on Closed event of the Form. Pls let me know how I can cleanup all EventHandlers for all Controls in the Form. IT IS URGENT. Please let me know.

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          You have to manually unsubscribe.

          private void Subscribe()
          {
          otherForm.TextChanged += new TextChangedDelegate(thisForm_TextChanged);
          }

          private void Unsubscribe()
          {
          otherForm.TextChanged -= new TextChangedDelegate(thisForm_TextChanged);
          }

          Regards Senthil _____________________________ My Blog | My Articles | WinMacro

          S 1 Reply Last reply
          0
          • S S Senthil Kumar

            You have to manually unsubscribe.

            private void Subscribe()
            {
            otherForm.TextChanged += new TextChangedDelegate(thisForm_TextChanged);
            }

            private void Unsubscribe()
            {
            otherForm.TextChanged -= new TextChangedDelegate(thisForm_TextChanged);
            }

            Regards Senthil _____________________________ My Blog | My Articles | WinMacro

            S Offline
            S Offline
            Shubhabrata Mohanty
            wrote on last edited by
            #5

            Actually the problem is that I don't know what all the EventHandlers each Derived Form is using. So it's become very difficult to remove all EventHandlers from each Derived Form manually. I just want to know if there is any way to remove all EventHandlers for all controls in the Form so that I can loop through all controls in the Form and Remove it in Base Form class. Please Help.

            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