Custom Activity - Probelm with EventSink Activity
Hello,
i tried to model a custom activity. This activity does contain of
a) InvokeMethod Activity
b) EventSink Activity
out of the activity galery delivered. I also implemented a Service which I added to the workflow engine in order to connect the method invokation and the event sink.
Then I build up a sequntial wf out of my custom activity.
The method invoke activity within my custom activity works properly, but when
my async. operation is finished and I want to raise the event to trigger the eventsink activity the event within the added service was null.
The same scenario works fine when i model this directly within a sequential wf.
Regards
CHS
[690 byte] By [
CHS] at [2008-2-22]
You need to make sure that the event is raised for the appropriate instance of the workflow. I am pasting some sample code that I wrote.
[
DataExchangeService]
public interface Service
{
void SomeMethod();
event EventHandler<WorkflowMessageEventArgs> SomeEvent;
} public class ServiceImpl : ClassLibrary1.Service
{
public WorkflowInstance instanceId;
public event System.EventHandler<WorkflowMessageEventArgs> SomeEvent;
public void SomeMethod()
{
ThreadPool.QueueUserWorkItem(new WaitCallback(RaiseSomeEvent),new WorkflowMessageEventArgs(instanceId.InstanceId));
}
private void RaiseSomeEvent(object state)
{
WorkflowMessageEventArgs e = (WorkflowMessageEventArgs)state;
if (SomeEvent != null)
{
Console.WriteLine("Raising some event for instanceID " + e.InstanceId);
SomeEvent(null, e);
}
}
}
And in your host you need to do the following:
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
ServiceImpl implLayer = new ServiceImpl();
workflowRuntime.AddService(implLayer);
workflowRuntime.StartRuntime();Type type = typeof(WorkflowConsoleApplication2.Workflow1);
implLayer.instanceId = workflowRuntime.StartWorkflow(type); Hope this helps.
- Vihang
Hello,
thank you for the information. The code you have pasted is the same code that I have implemented, but this code only works if I use the MethodInvoke Activity and EventSink Activity directly within a sequntial workflow.
What I tried then is to make a custom activity that contains also a MethodInvoke and a EventSink activity. The service (like the code above) I have to register at the workflow level. But when I use then this custom activity withina sequential WF the MethodInvoke does work, but the EventSink does not, because when i reach the code in my service implemntation where I want to fir the event that is sinked by mey eventsink activity within my custom activity in your code
private void RaiseSomeEvent(object state)
{
WorkflowMessageEventArgs e = (WorkflowMessageEventArgs)state;
if (SomeEvent != null)
{
Console.WriteLine("Raising some event for instanceID " + e.InstanceId);
SomeEvent(null, e);
}
}
}The SomeEvent is always NULL?!
So can I not transfere the MethodInvoke and the EventSink activity into a cuistom activity?! Is there also the problem with persisting child activities?!
Regards
CHS
CHS at 2007-9-9 >
