0

I'm using WF to run activities and I would like to invoke the activity synchronously on the same thread as the calling thread. How would I do that using WorkflowInvoker.Invoke? The following is my code snippet:

public int RunTransactionActivity(ActivityInputBundle inputBundle)
    {
            int returnCode = 100;

            ActivityFactory actFactory = new ActivityFactory();
            NativeActivity NA = null;

            NA = actFactory.GetTransactionActivity(inputBundle.ActivityName);


            Dictionary<string, object> inputs = new Dictionary<string, object>();
            inputs.Add("InputBundle", inputBundle);
            IDictionary<string, object> output;

            output = WorkflowInvoker.Invoke(NA, inputs);

            returnCode = Int32.Parse(output["ReturnCode"].ToString());

        return returnCode;

    }

The problem is, it seems, the activity (NA) is running on a different thread. Is there a way for me have the activity run on the same thread? I've read articles where the SynchronizationContext can be used to do that with the WorkflowApplcation, but I'm having issues using WorkflowApplication.Run() with output/return parameters.

ptn77
  • 567
  • 3
  • 8
  • 23
  • Trying to understand the question, and am wondering if you want the [WorkflowApplication.Run] method to wait until the workflow completes? The [Run] method will always spin up a new thread to run the workflow on. – ajawad987 Jun 24 '17 at 20:32
  • Is there a way to run WorkflowApplication.Run() with output/return parameters? – ptn77 Nov 28 '17 at 22:13

0 Answers0