13

I have a custom workflow activity (SharePoint 2010) with a Dependency Property defined as follows:

public static DependencyProperty TaskChangedEventPropertyEvent = DependencyProperty.Register("TaskChangedEventProperty", typeof(EventHandler), typeof(SPTaskActivity));

[Description("TaskChangedEventProperty")]
[Category("TaskChangedEventProperty Category")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public event EventHandler TaskChangedEventProperty
{
    add
    {
        base.AddHandler(SPTaskActivity.TaskChangedEventPropertyEvent, value);
    }
    remove
    {
        base.RemoveHandler(SPTaskActivity.TaskChangedEventPropertyEvent, value);
    }
}

In my parent workflow I have a ReplicatorActivity with:

private void replicateTasks_ChildInitialized(object sender, ReplicatorChildEventArgs e)
{
    SPTaskActivity spCreatePortfolioManagerTasks = e.Activity as SPTaskActivity;
    spCreatePortfolioManagerTasks.TaskAssignedTo = e.InstanceData.ToString();
    // ...
}

and the Event from my Activity hooked up to the following handler which never gets called:

private void taskFromSPTaskActivity(object sender, EventArgs e)
{
    //do stuff
}

This event is being raised via the onTaskChanged_Invoked event within the custom activity with:

base.RaiseGenericEvent<EventArgs>(TaskChangedEventPropertyEvent, this,e);

Can anyone provide any assistance/guidance as to why this might not be firing?

1
  • I think like @sumitkm... you can't raise an even handler in this scope... I have a question for you, Why do you raise an event? you'r managing an TaskChanged event and I suppose you can perform what you want in this procedure.
    – Bermudillo
    Commented Nov 4, 2013 at 13:33

2 Answers 2

1

What's preventing you from doing the 'stuff' in the onTaskChange_Invoked event? In other words where is the taskFromSPTaskActivity implemented?

If the event handler is not in scope of the WF runtime it will never be called.

If you are trying to implement a 'Raise External Event' and 'Handle External Event completed' type of scenario where the event completion is triggered by some factor external to the WF runtime (like button push on a page or some other SP List event), you will probably need to have two activities, one to Raise the Event (Subclass System.Workflow.Activities.CallExternalMethodActivity) and other to handle the event (Subclass HandleExternalEventActivity). Then glue these two together using a Service.

I can post some sample code if this is the direction you want to go.

1

I think the problem is the name of your DependencyProperty "TaskChangedEventPropertyEvent".

Here's the naming convention:

"The naming convention of the property and its backing DependencyProperty field is important. The name of the field is always the name of the property, with the suffix Property appended."

Link to MSDN
So you should change the actual Property "TaskChangedEventProperty"'s name to "TaskedChanged" for example and then change the name of your DependencyProperty "TaskChangedEventPropertyEvent" to "TaskedChangedProperty".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.