I still have problems getting an external event to work (in Beta 2). Gehnap showed the way EventArgs are handled now, but I still don't understand the mechanism. The greater problem I have is that I don't get the whole thing to work, cause the event is received, which I can see when I adjust a breakpoint to the activity, but the ReceiveName Event is never startet and the workflow comes to a halt, without throwing an exception. Below are all the files I have in my simple project. Can anyone spot my error And can anyone explain, how eParam in the Workflow should gets its content
Program.cs
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Runtime.Hosting;
#endregion
namespace SimpleWorkflow
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
new StartWorkflow();
}
}
// Die Klasse implementiert nun das Service Interface:
public class StartWorkflow
{
Hello NewHello = new Hello();
ExternalDataExchangeService ExService = new ExternalDataExchangeService();
static AutoResetEvent waitHandle = new AutoResetEvent(false);
public StartWorkflow()
{
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
workflowRuntime.AddService(ExService);
workflowRuntime.AddService(NewHello);
AutoResetEvent waitHandle = new AutoResetEvent(false);
workflowRuntime.WorkflowCompleted +=
delegate
(
object sender,
WorkflowCompletedEventArgs e
)
{ waitHandle.Set(); };
workflowRuntime.WorkflowTerminated +=
delegate
(
object sender,
WorkflowTerminatedEventArgs e
)
{
Console.WriteLine(e.Exception.Message);
waitHandle.Set();
};
WorkflowInstance instance =
workflowRuntime.CreateWorkflow
(
typeof(SimpleWorkflow.Workflow1)
);
instance.Start();
Console.WriteLine(instance.InstanceId.ToString() + " started \n");
NewHello.Greet("Hallo", instance.InstanceId);
waitHandle.WaitOne();
}
}
class Hello : IHello
{
public void HelloHost(string message)
{
Console.WriteLine("Message printed by host: " + message);
}
public event EventHandler<HelloEventArg> HelloWorkflow;
public Hello()
{
}
public void Greet(string Name, Guid InstanceID)
{
EventHandler<HelloEventArg> helloWorkflow1 = this.HelloWorkflow;
if (helloWorkflow1 != null)
helloWorkflow1(null, new HelloEventArg
(
InstanceID,
Name
));
}
}
}
Workflow1.cs
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
namespace SimpleWorkflow
{
public sealed partial class Workflow1: SequentialWorkflowActivity
{
public string Message;
public Workflow1()
{
InitializeComponent();
}
// neither this
private HelloEventArg eParam = default(SimpleWorkflow.HelloEventArg);
private void ReceiveName(object sender, ExternalDataEventArgs e)
{
if (eParam.Name == null)
{
Message = "";
}
else
{
Message = "Hello " + eParam.Name;
}
Console.WriteLine("Hello Problems");
}
// not thag
private void ReceiveName(object sender, ExternalDataEventArgs e)
{
Console.WriteLine("Hello Problems");
}
}
}
Workflow1.designer.cs
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Reflection;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
namespace SimpleWorkflow
{
public sealed partial class Workflow1
{
#region Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.CanModifyActivities = true;
this.handleExternalEventActivity1 = new System.Workflow.Activities.HandleExternalEventActivity();
//
// handleExternalEventActivity1
//
this.handleExternalEventActivity1.EventName = "HelloWorkflow";
this.handleExternalEventActivity1.InterfaceType = typeof(SimpleWorkflow.IHello);
this.handleExternalEventActivity1.Name = "handleExternalEventActivity1";
this.handleExternalEventActivity1.Invoked += new System.EventHandler<System.Workflow.Activities.ExternalDataEventArgs>(this.ReceiveName);
//
// Workflow1
//
this.Activities.Add(this.handleExternalEventActivity1);
this.Name = "Workflow1";
this.CanModifyActivities = false;
}
#endregion
private HandleExternalEventActivity handleExternalEventActivity1;
}
}
IHello.cs
using System;
using System.Workflow.Activities;
namespace SimpleWorkflow
{
// Definieren von Eventargs, damit uber einen
// Eventhandler Daten ausgetauscht werden konnen
// Die Klasse muss serialisierbar sein.
[Serializable]
public class HelloEventArg : ExternalDataEventArgs
{
private string _Name;
public string Name
{
get { return _Name; }
set { _Name = value; }
}
// Die GUID InstanceID muss immer ubergeben
// werden um eine konkrete Instanz des
// Workflows anzusprechen
public HelloEventArg(Guid InstanceID, string name)
: base(InstanceID)
{
this.Name = name;
}
}
// Das eigentliche Interface wird entsprechend deklariert
[ExternalDataExchange]
public interface IHello
{
// Eine Methode, die vom Workflow aus aufgerufen
// werden kann, wird definiert:
void HelloHost(string message);
// und ein Eventhandler wird definiert
// mit dem man ein Event des Workflows auslosen kann
event EventHandler<HelloEventArg> HelloWorkflow;
}
}
Bla blup

HandleExternalEventActivity hangs without exception
KushalMarthak
{
WorkflowRuntime workflowRuntime = new WorkflowRuntime();workflowRuntime.AddService(ExService);
ExService.AddService(NewHello); // <-- NewHello should be added to the ExternalDataExchangeService
sxd
Well that did work, and the part with the arguments I done like this:
private void ReceiveName(object sender, ExternalDataEventArgs e)
{
HelloEventArg eParam = (HelloEventArg)e;
if (eParam.Name == null)
{
Message = "";
}
else
{
Message = "Hello " + eParam.Name;
}
Console.WriteLine(Message);
}
what finally worked