Results 1 to 4 of 4

Thread: *Resolved* Do I have to remove event handlers?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    *Resolved* Do I have to remove event handlers?

    Right now I'm adding this to a process:
    VB Code:
    1. AddHandler Process.Exited, AddressOf Process_Exited
    2. Process.EnableRaisingEvents = True

    Now when the process is exited (or when I exit my app), should I go ahead and use RemoveHandler to remove the event handler? or it doesnt really mather?
    Last edited by MrPolite; Aug 12th, 2002 at 05:40 PM.

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    If you dont want the event to be raised again, you should remove it.
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by DevGrp
    If you dont want the event to be raised again, you should remove it.
    well the thing is that I'm closing my program and so the event wont be raised I'm just wondering if it is bad to leave it like that (without removing it)

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    No, you can leave it. See when a forms constructor is called when it is being created, the initialize method is called. That is where VS puts all the code to initialize all the controls on the form and their associated events. It does the same code you would do when you add in your event handlers, just it is in the initialize method. When your form is destroyed (you exit your app) all instance data is destroyed with it, so it doesn't matter if you have event handlers. They are just delegates anyway, an object that the garbage collector will handle for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width