EventSubscription not called in threaded callback

Topics: CAB & Smart Client Software Factory
Apr 26, 2006 at 11:51 AM
originally posted by: DJinOrlando

Hoping for some help here.

I have an event publication in a workitem controller. The declaration resembles:

EventPublication("SomeEventTopicName", PublicationScope=WorkItem)
public event EventHandler SomeEvent;
private void onSomeEvent()
if (SomeEvent != null)
SomeEvent(this, new EventArgs ());

As part of the Run initialization phase of the workitem controller, I've created a view using WorkItem.Items.AddNew<> (); The view gets instantiated and is correctly built using ObjectBuilder (all the right things are injected). Within this view's presenter, I have a method to catch the above-mentioned event:

public void SomeEventHandler(object sender, EventArgs e)

Within the workitem controller code, I make a call to a service agent (that in turn calls a web service). I use the delegate callback pattern that is in the AppraiserWorkbench sample. Within the delegate callback, I raise the event. That code resembles:

private void someMethodInController()
_myServiceAgent.GetSomeInformation(object inputParam,
delegate (bool success, object someInformationOutput)
if (success)


My problem is that the event subscriber method in this scenario never gets called. I've tried any number of combinations of PublicationScope values in the Publication and ThreadOption values in the Subscription. The method never gets called.

The view has been decorated w/ the SmartPart attribute. The view's presenter actually successfully catches other events that are raised from this workitem controller in exactly the same fashion.

Now for the fun part - If I step through the code, including all of the cab code around firing and handling the events, it works. If I try to just run the application, it doesn't.

I don't get any exceptions; it just never works.
Apr 26, 2006 at 12:13 PM
originally posted by: DJinOrlando

It never fails. I stew over a problem for 3 or 4 hours, finally break down and post a message on the board, and bam the solution comes to me.

In my Run initialization, I was making the calls to get the data BEFORE I was loading the views. So, the callback threads were getting back before the view was there to subscribe to the event.

Threads are definitely a two-edged sword.
Apr 26, 2006 at 12:52 PM
originally posted by: ChrisHolmes

"It never fails. I stew over a problem for 3 or 4 hours, finally break down and post a message on the board, and bam the solution comes to me."

This happens to me every time. It's probably a Murphey's Law or something.