473,383 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Unsubscribing from events.

I came across the following code in the .NET Framework:

((IBindingList) list).ListChanged -= new
ListChangedEventHandler(this.List_ListChanged);

In other places, they hold onto a reference to the original event handler
instance and unsubscribe that. I've always held the references and
unsubscribed the original myself.

Unsubscribing from a new instance instead of the original instance just
seems wrong. Yet one of my co-workers claims this actually works. Does it?

Pete
Nov 16 '05 #1
2 1708
Pete,

Yes, it works. I wouldn't waste the field to hold onto this. It's the
method that is the identity of the delegate, not the instance of the
delegate itself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Pete Davis" <pd******@NOSPAM.hotmail.com> wrote in message
news:87********************@giganews.com...
I came across the following code in the .NET Framework:

((IBindingList) list).ListChanged -= new
ListChangedEventHandler(this.List_ListChanged);

In other places, they hold onto a reference to the original event handler
instance and unsubscribe that. I've always held the references and
unsubscribed the original myself.

Unsubscribing from a new instance instead of the original instance just
seems wrong. Yet one of my co-workers claims this actually works. Does it?

Pete

Nov 16 '05 #2
That's what my co-worker said, but I just wanted to be sure. Thanks
Nicholas.

Pete

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Oc**************@TK2MSFTNGP09.phx.gbl...
Pete,

Yes, it works. I wouldn't waste the field to hold onto this. It's the method that is the identity of the delegate, not the instance of the
delegate itself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Pete Davis" <pd******@NOSPAM.hotmail.com> wrote in message
news:87********************@giganews.com...
I came across the following code in the .NET Framework:

((IBindingList) list).ListChanged -= new
ListChangedEventHandler(this.List_ListChanged);

In other places, they hold onto a reference to the original event handler instance and unsubscribe that. I've always held the references and
unsubscribed the original myself.

Unsubscribing from a new instance instead of the original instance just
seems wrong. Yet one of my co-workers claims this actually works. Does it?
Pete


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Vince C. | last post by:
Hi. I'd like to trap ADO Recordset object events in my ASP script (either VBS or JS, no preference). I've tried (in VBS) writing a Sub rs_RecordChangeComplete( adReason, cRecords, pError,...
3
by: Sasha | last post by:
Hi everyone, Here is my problem: I have the following classes: - DataNode - this class is designed to hold some data and will be contained in a tree like data structure DataTree. When...
4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on...
11
by: Nicky Smith | last post by:
Hello, I'm studying a book on VB.net Win apps, and I'm reading a section on events and delegates and raising events. Is it just me, or is this not just subs dressed up as something else? I...
4
by: Albert | last post by:
Bye, all: I'm unsubscribing from thiis Usenet group! You guys only talk SHIT Albert
4
by: David Veeneman | last post by:
Do I need to unsubscribe from an object's event before I point the object variable to a new object? I have a method that subscribes an event handler to the ListChanged event of a list. The list...
5
by: Daniel | last post by:
Hey guys When you hook an event (c# 2.0 syntax): myEvent += MyMethodToFire; You need to also unsubscribe it to avoid a resource leak so that the object it is in gets garbage collected like so...
14
by: xoozlez | last post by:
Hi there, I have a registration form where I like to filter out the past events of 2007. This is the code I am using : strSQL = "SELECT EventID, EventName, EventDateBegin, EventDateEnd,...
1
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.