Using ActivityFunc with InvokeDelegate in workflow designer RRS feed

  • Question

  • Hi,

    I'm trying to configure a Workflow with an InvokeDelegate activity bound to a ActivityFunc defined in my host.

    I'm using VS2012 with WF 4.5.

    I made a very simple test workflow named "WriteF" using the designer:

    - add a flowchart

    - add a property to the flowchart named "Action" of type ActivityFunc<string>

    - add an InvokeDelegate and select the "Action" property as delegate

    - add a variable named "ActionResult" to the flowchart

    - open DelegateArguments properties of InvokeDelegate and set the Result output argument value to "ActionResult"

    - add WriteLine activity and set Text argument to "ActionResult"

    I've created a simple custom activity:

    public class TestActivity : CodeActivity<string>
    	protected override string Execute(CodeActivityContext context)
    		return "Hello Workflow";

    Then, I've added the following code to my main program (console app):

    WriteF wf = new WriteF();
    wf.Action = new ActivityFunc<string>()
    Handler = new TestActivity()

    But nothing output to the console and when I debug, the ActionResult variable remains null.

    Can anyone explain what I'm doing wrong?

    I cannot find any sample of ActivityFunc used with InvokeDelegate in a designer on the web.

    Thank you.

    • Edited by flachr Thursday, February 21, 2013 10:53 AM
    • Changed type flachr Thursday, February 21, 2013 12:03 PM
    Thursday, February 21, 2013 10:51 AM


All replies

  • Not really sure that I understood what do you want to achieve, but in most situations you don't need activity delegates. Probably if you post the full sample it would be clear.

    Usually to pass data into workflow/activity and return data back InArgument and OutArgument are used. See corresponding section of Using WorkflowInvoker and WorkflowApplication topic.

    If you need to use Activity Delegates, please have a look at Using Activity Delegates. There are some good samples.

    Friday, February 22, 2013 8:08 AM
  • My final goal is to inject external data into the workflow on demand not as argument passed before execution.

    For example you have an application that process a csv file interactively :

    - first the user is asked for a file to process (trivial :)

    - a workflow is launched with the file as input argument

    - the file is analyzed

    - if the file contains dates (so in a particular branch of the workflow), the workflow needs to know date format to check and process them

    - workflow notify host with an ActivityFunc

    - host ask user for format then return it through the result of an ActivityFunc

    About my first question, it is really about using ActivityFunc inside the designer. In a class this mechanism is working.

    Thank you.

    Friday, February 22, 2013 9:30 AM
  • Check WPF and WF Integration in XAML sample. It could give you an idea how it could be implemented.

    • Marked as answer by Molly Chen_ Thursday, February 28, 2013 3:36 AM
    Friday, February 22, 2013 8:36 PM