Threads in WorkflowApplication RRS feed

  • Question

  • Hi,

    I'm using a System.Activities.WorkflowApplication to execute workflow activities. The advantage of an application, is that I can use extentions to control my activity. I'm using a System.Activities.Tracking.TrackingParticipant extention to have a log of the methods executed in the activity.
    I start the activity with the Run method on the WorkflowApplication class.

    Currently each time the code creates a new activity, a new instance of Workflowapplication is made and run is called. Since the workflowapplication is a proxy to the actual workflow instance that is managed by the workflow runtime, this is no problem.
    The only problem I have, is that I can not manage the threads that are used for executing the workflow. I also do not know if I should. What happens when I run 1000 activities in a row. Is the run method going to fail? Is the server going down?
    It would all be solved if I could let the activities be executed synchronously. System.Activities.WorkflowInvoker.Invoke is no option, because extentions are not possible.

    Can anyone help me?
    The only answer I currently have, is let the initial thread that starts the activity, let this thread wait until the completed or aborted method is called.


    Saturday, January 7, 2012 2:27 PM


  • Hi Raf,
    Normally it is not necessary to manage the threads used by WorkflowApplication. WorkflowApplication will run workflows on a limited size pool of threads.

    Also normal is that each workflow (and activities inside it) do not require a very significant amount of thread (CPU+sleep) time to run their Execute methods, and so many workflows can be executed on a single thread. Sometimes using AsyncCodeActivity is helpful in ensuring the workflow is using thread time.

    The ability to manage the threads used by WorkflowApplication does exist, if you need it, via SynchronizationContext property. You can use this to force synchronous execution or execution on a specific thread.

    If you have more questions, please reply.

    • Proposed as answer by Horizon_Net Saturday, January 7, 2012 9:33 PM
    • Marked as answer by LeoTang Sunday, January 15, 2012 2:52 PM
    Saturday, January 7, 2012 8:03 PM