Knut Espen Bergby

I have made several custom activities. Now I want to implement ExecuteCode like in the Code activity. ExecuteCode should be able to call a method in the workflow.

Ideally I want my custom activity to behave just like the Code activity: When the user double clicks, a method should automatically be created in the workflow and the method should be bound to the activity.


Re: Windows Workflow Foundation ExecuteCode in workflow from Custom Activity

Angel Azcarraga - MSFT

Here you go:

[DefaultEvent("ExecuteCode")]
public sealed class MyCustomActivity : Activity
{
    
public static readonly DependencyProperty ExecuteCodeEvent = DependencyProperty.Register("ExecuteCode", typeof(EventHandler), typeof(MyCustomActivity));

     public event EventHandler ExecuteCode
     {
         
add
         
{
              
base.AddHandler(ExecuteCodeEvent, value);
          }
         
remove
         
{
              
base.RemoveHandler(ExecuteCodeEvent, value);
          }
     }

     protected override sealed ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
     {
         
base.RaiseEvent(MyCustomActivity.ExecuteCodeEvent, this, EventArgs.Empty);
         
return ActivityExecutionStatus.Closed;
     }
}






Re: Windows Workflow Foundation ExecuteCode in workflow from Custom Activity

Knut Espen Bergby

Thanks. It works like a charm :-)