Running a WI from another module w/ diff params

Topics: CAB & Smart Client Software Factory
Jul 7, 2006 at 6:51 PM
originally posted by: sklett

I would like to run a WorkItem in module A from module b, but pass different parameters to the WorkItem. Doesn't make sense, I know.

What I'm doing now is firing an event from moduleB to start the workitem in ModuleA, something like this:
// ModuleB
new EventArgs<string>(firmware.Filename),

// ModuleA
public void ProgramTargetHandler(object sender, EventArgs<string> e)
// Add the Programmer WorkItem, start the programming process
// and when complete, remove the Workitem
ControlledWorkItem<ProgramTargetWorkItem> wi =

if (wi == null)
wi = WorkItem.WorkItems.AddNew<ControlledWorkItem<ProgramTargetWorkItem>>(e.Data);


This works fine. BTW, if you have a suggestion for a better way to do this, please share.

As you can see here I pass a path to a file in the EventArgs. What I would like to do is be able to pass a byte[] of the contents of that same file rather than the path. This is for performance reasons.

The only way I can think to do this is to create another EventSubscription with a handler that expects EventArgs<byte[]>.

This solution may not even work, I haven't tried it, but even if it does, I'm not comfortable with it, feels "hacky". Can any of you think of another way I can accomplish this while keeping things nice and decoupled?

There are times when ModuleB will be running the ModuleA WI over and over and over, it's these cases where I want to pass the byte[] for performance reasons, other times passing the path is the easier thing to do.

Thanks for reading,
Jul 8, 2006 at 5:24 AM
originally posted by: ChrisHolmes


You can create custom EventArgs to pass data around using EventBrokerEvents. You are not confined to using just plain old EventArgs :)
Jul 8, 2006 at 9:34 AM
originally posted by: sklett

Hi Chris, how are you?

Do you mean something like "ProgramTargetEventArgs" class with properties like:
bool useByteData;
string filename;
byte[] data;

Hmmm... maybe that is cleaner? I like that. :0) If that's what you were suggesting, thanks!

How is your project doing?

Thanks for the post!
Jul 8, 2006 at 9:43 AM
originally posted by: ChrisHolmes

Good Steve :-)

Yeah, that's exactly what I mean. You can create any EventArgs you want with whatever properties you need to pass around. I do this quite a bit with my own EventBroker Events to pass key values around (for certain modules to access shared State items) and because it's just clearer code. I can tell just by looking at the EventArgs type what the Event is supposed to be doing.
Jul 25, 2006 at 6:13 AM
originally posted by: JKraft4PIT

I have a event publication/subcription that passes a entity and this is how I do it.

<EventBroker.EventPublication("MyEventName", EventBroker.PublicationScope.WorkItem)> _
Public Event ConnectionChanged As EventHandler(Of DataEventArgs(Of ConnectionState))

<EventSubscription("MyEventName")> _
Public Sub ConnectionChanged(ByVal sender As Object, ByVal dataArgs As DataEventArgs(Of ConnectionState))

End Sub

You have to import Microsoft.Practices.CompositeUI.Utility

This is how I send different types through event broker.