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