locked
ThrottledParallelForEach thread safety RRS feed

Answers

  • Hi, Alex

    ->"This is not a problem. The problem is that OnBodyComplete method calls enumerator.MoveNext(). So if more then one child activity complete at the same time this enumerator could be accessed by multiple threads."

    You will never encounter such a problem. Since branches are running in ONE thread. as far as I know these executing branches are stored in a stack, once a branch is idled, it will be poped out and another branch will continue executing. So, actually no two branches will executing at the same time. they are executing one by one. the shifting process is so quick that they seem like executing asynchronously.

    Hope it helps
    Regards
    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support. My Blog:http://xhinker.com "Microsoft Windows Workflow Foundation 4.0 Cookbook"
    • Marked as answer by Andrew_Zhu Friday, October 1, 2010 8:13 AM
    Tuesday, September 28, 2010 8:26 AM
  • The parallel activity schedules activities to run sequentially, but unlike a sequence activity, an idle activity won't block the workflow- if a child activity goes idle, the next scheduled activity will run until it idles, and so on. If none of the activities go idle, a parallel activity functions the same as a sequence activity.
    • Marked as answer by Andrew_Zhu Friday, October 1, 2010 8:13 AM
    Wednesday, September 29, 2010 5:15 PM

All replies

  • The various parallel activities don't actually run multithreaded- they only run child activities when a previously run child goes idle. 

    If an asynchronous activity goes idle and is later resumed, then that activity will run on another thread.

    You can add a synchronization context to the WorkflowApplication host object using the following method:

    http://msdn.microsoft.com/en-us/library/system.activities.hosting.workflowinstance.synchronizationcontext.aspx

    Monday, September 27, 2010 6:47 PM
  • This is not a problem. The problem is that OnBodyComplete method calls enumerator.MoveNext(). So if more then one child activity complete at the same time this enumerator could be accessed by multiple threads.
    Monday, September 27, 2010 6:58 PM
  • I've contacted the sample author to find out more information about this issue- if it's a problem within the context of the workflow runtime, or if there's a recommended solution-
    Monday, September 27, 2010 9:08 PM
  • Hi, Alex

    ->"This is not a problem. The problem is that OnBodyComplete method calls enumerator.MoveNext(). So if more then one child activity complete at the same time this enumerator could be accessed by multiple threads."

    You will never encounter such a problem. Since branches are running in ONE thread. as far as I know these executing branches are stored in a stack, once a branch is idled, it will be poped out and another branch will continue executing. So, actually no two branches will executing at the same time. they are executing one by one. the shifting process is so quick that they seem like executing asynchronously.

    Hope it helps
    Regards
    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support. My Blog:http://xhinker.com "Microsoft Windows Workflow Foundation 4.0 Cookbook"
    • Marked as answer by Andrew_Zhu Friday, October 1, 2010 8:13 AM
    Tuesday, September 28, 2010 8:26 AM
  • What do you mean "branches are running in ONE thread"? This is parallel activity we are talking about. What is the point of parallel activity if it runs branches on a single thread?

    We use this activity in our build process. Every branch takes long time to execute and I can see those branches running in parallel.

    Tuesday, September 28, 2010 4:35 PM
  • The parallel activity schedules activities to run sequentially, but unlike a sequence activity, an idle activity won't block the workflow- if a child activity goes idle, the next scheduled activity will run until it idles, and so on. If none of the activities go idle, a parallel activity functions the same as a sequence activity.
    • Marked as answer by Andrew_Zhu Friday, October 1, 2010 8:13 AM
    Wednesday, September 29, 2010 5:15 PM
  • How do you explain that our builds (essentially InvokeProcess activity that run for a long time bacause they invoke MSBuild) are running in parallel? I must be missing an important part of parallel activities internals.
    Wednesday, September 29, 2010 5:38 PM
  • If the activity itself is waiting for input from MSBuild or the invoked process, it would go idle at that point, and the Parallel activity would schedule the next build-

    Wednesday, September 29, 2010 7:15 PM