I came across the following code in the .NET Framework:
((IBindingList) list).ListChang ed -= new
ListChangedEven tHandler(this.L ist_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 2 1724
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.co m
"Pete Davis" <pd******@NOSPA M.hotmail.com> wrote in message
news:87******** ************@gi ganews.com... I came across the following code in the .NET Framework:
((IBindingList) list).ListChang ed -= new ListChangedEven tHandler(this.L ist_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
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.c om> wrote in
message news:Oc******** ******@TK2MSFTN GP09.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.co m
"Pete Davis" <pd******@NOSPA M.hotmail.com> wrote in message news:87******** ************@gi ganews.com...I came across the following code in the .NET Framework:
((IBindingList) list).ListChang ed -= new ListChangedEven tHandler(this.L ist_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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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, adStatus, pRecordset ) - rs being a server-side
ADODB.Recordset object - but it doesn't get called whenever rs is moved (I
browse it in a loop).
Is...
|
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 DataNode is changed, it raises
"Changed" event. The class has a reference to the DataNode it is being
contained in:
- DataTree - tree like data structure...
|
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 when to use one over another? If
anyone could provide any additional info, your comments, best practices, any
good articles, specific examples, etc....
|
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 mean, for one, delegates point to subs, so when you call a delegate,
why not just call the sub dierectly and not bother adding the extra
code...
|
by: Albert |
last post by:
Bye, all: I'm unsubscribing from thiis Usenet group!
You guys only talk SHIT
Albert
| |
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 is attached to a calendar, so every time a new date is
selected, the list is recreated for the new date. The code then subscribes
the event handler...
|
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 : myEvent -= MyMethodToFire;
That's all fine, but when you use visual studio to create events for objects
it never creates an unsubscribing...
|
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, EventTimeBegin, Category FROM Events WHERE EventDateBegin >'01/01/2008' AND Events.Category LIKE '3' OR Events.Category LIKE '4' OR Events.Category LIKE '5'...
|
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 events when click on that date that perticular event displyed in a text box.But my requirement is to when click on that date that related event...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |