Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / October 2003

Tip: Looking for answers? Try searching our database.

Has anyone seen a delegate lose track of its target?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Walrath - 16 Oct 2003 20:06 GMT
I have written code the subscibe to a delegate that is called at a specific
interval.  Initially, everything is fine, and the delegate works.  However,
after some (seemingly random) amount of time, the delegate appears to get
disconnected.

I have trace statements around the delegate call, each showing that the
delegate call is ocurring.  I am not getting any NullReferenceExceptions,
which I should if the delegate is null.  So it appears the delegate is being
called, but the target is lost, so the client never does its work.

I never had this problem with framework v1.0.  I'm using v1.1 now.

Has anyone seen anything like this?

Thanks,

Greg
Shashank Welankar - 17 Oct 2003 07:07 GMT
I guess the object that is reciving the events get unloaded/deallocated for
some reasons.

possible reasons:
1. You might have defined it on the stack in some local function.
2. You are setting the reference to Nothing at some point during execution.

Shashank

> I have written code the subscibe to a delegate that is called at a specific
> interval.  Initially, everything is fine, and the delegate works.  However,
[quoted text clipped - 13 lines]
>
> Greg
Jon Skeet [C# MVP] - 17 Oct 2003 08:12 GMT
> I guess the object that is reciving the events get unloaded/deallocated for
> some reasons.
>
> possible reasons:
> 1. You might have defined it on the stack in some local function.
> 2. You are setting the reference to Nothing at some point during execution.

Neither of those should lose the object though - the delegate itself
has a reference to the target.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jon Skeet [C# MVP] - 17 Oct 2003 08:13 GMT
> I have written code the subscibe to a delegate that is called at a specific
> interval.  Initially, everything is fine, and the delegate works.  However,
[quoted text clipped - 9 lines]
>
> Has anyone seen anything like this?

Can't say I've seen it - but if the call is definitely occurring, could
you put some kind of counter in your class (incremented one per
instance, and keep the value as an instance variable), and in your
trace output which instance number is being used?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Dave - 17 Oct 2003 10:57 GMT
I would look at the target first - perhaps it went out of scope, perhaps it
removed itself. Another possibility is that the delegate stops getting
invoked by the interval generating mechanism. I doubt that the delegate
"loses" the target.

> I have written code the subscibe to a delegate that is called at a specific
> interval.  Initially, everything is fine, and the delegate works.  However,
[quoted text clipped - 13 lines]
>
> Greg

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.