listening to internal events  
Author Message
sirmmo





PostPosted: Windows Workflow Foundation, listening to internal events Top

Hi!

I have a little problem handlig some events raised by activities within a workflow.
This s the code:


public partial class Activity1 : RaiseExternalEventActivity, IEvents
{
public Activity1()
{
InitializeComponent();
evento += this.eventoRaised;
}

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{

OnEvento(this, new ExternalDataEventArgs(this.WorkflowInstanceId));

return ActivityExecutionStatus.Closed;
}



#region IEvents Members

public event EventHandler<ExternalDataEventArgs> evento;

private void OnEvento(object sender, ExternalDataEventArgs ea)
{
if (evento.GetInvocationList() != null)
evento(sender, ea);

}

private void eventoRaised(object sender, ExternalDataEventArgs a)
{
Console.WriteLine("evento lanciato...");
}

#endregion

public override event EventHandler<ExternalDataEventArgs> StandardEvent
{
add { evento += value; }
remove { evento -= value; }
}


The problem is that nonetheless "evento" is raised, my handler is never called. This is pretty strange...

I assign the handler this way...


eventManagementData.SenderActivity.StandardEvent += StandardHandler;


Thank you for the help...
Marco




Software Development for Windows Vista14  
 
 
Serge Luca





PostPosted: Windows Workflow Foundation, listening to internal events Top

Marco,

if I understand your code, your object sends an event to itself

Why don't you use the normal (.net) way of sending an event in this case

public partial class Activity1: SequenceActivity
{
public event EventHandler evento;
public Activity1()

{
InitializeComponent();
evento += new EventHandler(Activity1_myEvent);
}

void Activity1_myEvent(object sender, EventArgs e)
{
Console.WriteLine("event called");

}

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
if (evento != null)
evento(this, new EventArgs());
return ActivityExecutionStatus.Closed;
}

 
 
sirmmo





PostPosted: Windows Workflow Foundation, listening to internal events Top

Yes, it's true. It sends an event to itself, but that's not where I get the problem.
I can't listen to that event from anything else but the activity itself. That's why I'm asking...

 
 
Serge Luca





PostPosted: Windows Workflow Foundation, listening to internal events Top

Marco

if I understand correctly you want to be able to send an event from an Activity A that could be handled by Activity B If this is what you want, one way to achieve this is to call a method of the localService that triggers the event (associated with the instanceid).

I don't know if that helps you...

 
 
sirmmo





PostPosted: Windows Workflow Foundation, listening to internal events Top

It does, in fact :D
Thank you very much :)

 
 
Serge Luca





PostPosted: Windows Workflow Foundation, listening to internal events Top

my pleasure;

now, if you want more informations about some event interfaces, I suggest the following reading : http://www.winterdom.com/weblog/CommentView,guid,6993b37a-eed1-45fc-b441-96f9ef6c446c.aspx

+ the FileSystemWatcher activity wf sdk sample

 
 
sirmmo





PostPosted: Windows Workflow Foundation, listening to internal events Top

OK... I'm trying now to use specific CallExternalMethodActivities. The problem is that I get the following error...
Method 'EventManagementService.IEventManagementServiceCommuncation.RaiseEvent' not found.

I don't understand...