Event raising in workflow ?

Hi

Can my workflow have some events that I will handle in my application [for example windows forms code] ?
I have application that should run in infinite while loop and stop for one hour after each succesful execution.
So I would make while with with true condition and on the and of sequence I'd put Delay activity.
But how do I know what's going on in my workflow if it never ends ? It will finally be used in Windows Service so it should be running every our do what it has to do and than go idle... But for now I'd like it to communicate with me by some messages. So if certain conditions happen I'd like to have an event raised.

Can I do such thing in workflow ? If yes, tell me how :)

Jarod

[742 byte] By [Jarod.Net] at [2007-12-28]
# 1

You can definitely do that. : )

In fact, here's a link to a scenario that is almsost exactly what you want (minus one thing): http://www.dennispi.com/?p=104

The missing piece is how to communicate what your workflow is doing. The scenario linked above never communicates outside, it simply waits, does some work, then does it again. In your case, you'd want to include a CallExternalMethod activity which would make a call outside to a local service (which you implement). Your local service can then handle the call as it desires (log something, process data, etc.). If you want the local service to then call back into the workflow, you would use a HandleExternalEvent activity and raise an event from your local service back into the workflow. Please refer to the documentation for more information on messaging in WF: http://msdn2.microsoft.com/en-us/library/ms735947.aspx

Thanks!
Angel

AngelAzcarraga-MSFT at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 2

But can I do sth like this:

In my workflow class:

public event EventArgs MyEvent;

And then in service code:

for example... : instanceOfWorkflow.MyEvent += delegate(object sender, EventArgs e) { // do sth };

Jarod

Jarod.Net at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 3

No, the workflow does not raise custom defined events to the outside. Remember that the WorkflowInstance class is agnostic of specific implementation or state of the instance it wraps - it's generic for all workflow instances.

If you want something like this, then you expose an event (e.g. MyEvent) on your local service, and when your workflow calls into your local service, you would in turn raise that event to whoever is listening from inside your method.

-Angel

AngelAzcarraga-MSFT at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 4

So let's say I have defined my event in my local service calledm MyService and I have on a diffrent project MyWorkflow. If I want to define CallBackExternal method it means I must have some reference to MyService ? But If my service or windows forms compiles to a normal .exe file how should I do this ? Making external class referencing in both ( just to have some stupid event fired ) seams a bit a uncofortable and how it looks from architectural point of view ?

Jarod

Jarod.Net at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 5

Hi,

The communication pattern you want to implement involves the usage of the CallExternalMethodActivity (and HandleExternalEventActivity in case the workflow has to wait for a certain event. Not mandatory in your case). The local service mentioned by Angel is not your Windows service, it is just a WF specific communication abstraction (implementing a certain interface and communication pattern between the workflow and the outside world, decorated w/ certain attribute etc.). Internally, in the code associated w/ your workflow's CallExternalMethodActivity, you may call your Windows service or any other method that may raise an event to interested parties/host. In other words, the event cannot belong to the workflow instance but to your host, to another service etc. and you can always trigger it through this WF communciation mechanism.

You should probably start by looking at the WF Communication samples coming out-of-the-box or at:

http://msdn2.microsoft.com/en-us/library/ms741731.aspx

Thanks!

ConstantinMihai-MSFT at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified