Click here to Skip to main content
15,892,059 members
Articles / Programming Languages / C#
Tip/Trick

The simplest trick to remove an event handler

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
15 Sep 2011CPOL 15.5K   1   3
Trick to remove an event handler out of the scope of the handler
WorkStarted is an event (with existing handler):

C#
this.WorkStarted -= this.WorkStarted;


The handler method could be out of the scope (as parameter in another method for instance). It works only in the class that defines the event (added by Andrew Rissing).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Poland Poland
Complicated

Comments and Discussions

 
Generalnice .. Pin
Denno.Secqtinstien17-Nov-11 23:38
Denno.Secqtinstien17-Nov-11 23:38 
GeneralThis only works though from within the class that defines th... Pin
Andrew Rissing14-Sep-11 3:53
Andrew Rissing14-Sep-11 3:53 
GeneralRe: not so much work to do this either. dgw.Scroll -= dgwSetupH... Pin
MrDeej20-Sep-11 10:17
MrDeej20-Sep-11 10:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.