Firing a custom event, but getting handled twice

Topics: CAB & Smart Client Software Factory
Nov 12, 2005 at 7:28 AM
originally posted by: DLorenz

I'm firing off events manually (for function keys, since they are ever changing), but the subscriber ends up receiving the event twice. This is the code I'm running to fire off the event (It's in VB.NET):

Private Sub FireCustomEvent(ByVal EventURI As String, ByVal EventScope As PublicationScope)
If Not EventURI Is Nothing AndAlso EventURI.Length > 0 Then
Dim evtService As IEventTopicCatalogService = Me.GetWorkItem.Services.Get(Of IEventTopicCatalogService)(True)
Dim evtTopic As EventTopic
If Not evtService.Contains(EventURI) Then
evtTopic = New EventTopic(EventURI)
evtService.Add(evtTopic)
Else
evtTopic = evtService(EventURI)
End If

evtTopic.Fire(_functionKeyText.GetMyWorkItem, EventArgs.Empty, _functionKeyText.GetMyWorkItem, EventScope)
End If
End Sub

After calling evtTopic.Fire, the subscriber will get the event twice. Is there an obvious reson why? EventScope is normally marked as Descendants. Is it possible that the call to descendants ends up getting the same subscriber twice? Thanks.
Nov 17, 2005 at 6:31 AM
originally posted by: DLorenz

This bug wasn't addressed in the RTW. Though, RTW made the call easier so now I simply do:

Private Sub FireCustomEvent(ByVal EventURI As String, ByVal EventScope As PublicationScope)
If Not EventURI Is Nothing AndAlso EventURI.Length > 0 Then
GetWorkItem.EventTopics(EventURI).Fire(_functionKeyText.GetMyWorkItem, EventArgs.Empty, _functionKeyText.GetMyWorkItem, EventScope)
End If
End Sub
Nov 19, 2005 at 6:11 AM
originally posted by: DLorenz

Nevermind, I had a paging view and controller I inherited from. There ended up being 2 instances of the same Controller, so it looked like it was being handled twice.
Jun 27, 2006 at 11:02 PM
originally posted by: _JERKER_

Thanks for publishing your problem - and solution.

I had the same problem and what helped me was, when debugging, to check the controller's hashcode in the event handler.

Obvious to some, but not to all of us...


BR
Jerker