Search code examples
workflow-foundation-4

Is the TrackingParticipant.Track method thread safe>


I'm using a custom TrackingParticipant to update some state information in the database. Since in the database there are sometimes incorrect values, I'm thinking that the behavior of the Track method is not the one I expect. Documentation says: "When implemented in a derived class, used to synchronously process the tracking record" I intended that all records are executed one after the other, at least for the same state machine instance.

Am I wrong? Should I always protect the Track implementation with a critical section? I'm wondering about overall performances...anyway, of course, the priority is that the system works as expected.

Thanks


Solution

  • You need to implement the Track() method, so there is no question of it being thread safe, you decide.

    The workflow runtime will not continue until Track() is finished so you will never get multiple Track() calls concurrently. That means that "slow" database inserts will affect you workflow performance. The best thing for performance is to put data in a concurrent in-memory queue and use a background thread to do the actual database inserts.