Okay, make an example here:
- I have UserControl A, UserControl B, UserControl C and one Windows Form.
- This Windows Form is only started with UserControl A.
- UserControl C has [Next] and [Back] buttons.
- Say, UserControl A is declared with an event handler. One of function in UserControl A will actually raise the event call to execute one function at UserControl C.
- So, at UserControl C, I have to add with
“UserControlA.OneFunction += this.UserControlC_Function;”
- If I click Next button at UserControl C, it will dispose the UserControl A and add new UserControl B to the Windows Form. But I never remove this event handler manually.
One of the function in UserControl A is the caller (where event is declared).
One of the function in UserControl C is the listener.
So, these are my questions:
- Should I manually remove the handler before UserControl A disposed?
- Will this User Control A dispose automatically remove the handler that declared previously?
- Should I add this somewhere?
“UserControlA.OneFunction -= this.UserControlC_Function;”
1 Answer