I'm working with the SqlTrackingService in Workflow Foundation and I'd like to make sure my tracking data is persisted before I continue executing any code. From what I've read, the tracking service should do one of the following:
- If the tracking service is transactional, tracking data is persisted whenever workflow state is persisted (such as on idle).
OR
- If tracking service is non-transactional, tracking data is persisted immediately.
What I really need is the second option. The first reply here suggests that it's possible, albeit with possible performance issues. However, it doesn't appear to be working quite right.
In my activity, I have wired up to a queue. When a queue item is available, I'm executing the following (just for testing):
private void TestTracking()
{
TrackData("Key", new TrackingDataContainer("Value", Name, DateTime.Now));
var sqlTrackingQuery = new SqlTrackingQuery(ConnectionString);
SqlTrackingWorkflowInstance sqlTrackingWorkflowInstance;
sqlTrackingQuery.TryGetWorkflow(WorkflowInstanceId, out
sqlTrackingWorkflowInstance);
var events = sqlTrackingWorkflowInstance.UserEvents
.Where(p => typeof (TrackingDataContainer)
.IsAssignableFrom(p.UserData.GetType()))
.Where(p => p.UserDataKey == "Key")
.ToList();
MessageBox.Show(events.Count().ToString());
}
I expect that the first time I make a queue item available, I see the message 1. Instead, it is 0. If I post another queue item, I expect 2, but have been seeing 1. I speculate that if I were to add queue items faster, I might see 0 in both cases.
To me, this seems asynchronous. I've also tried putting in Thread.sleep calls which appear to work, but is a nasty way of doing things. Any suggestions?