Windows Workflow Foundation and ThreadSafety
When adding ExternalDataExchange services to the runtime it needs to be noted that theses methods are all NOT threadsafe. The runtime will allow you to add multiple instances of the same exchange service to the runtime, but when you call the GetService<T>() method on the runtime, an exception will be thrown. The following will protect you against these problems.
private static object _lockObject = new object();
T service;
lock (_lockObject)
{
service = (T) defaultService.GetService(typeof (T));
if (service == null)
{
service = (T) TypeLoader.Load(typeof (T).AssemblyQualifiedName);
if (service == null)
{
throw new ArgumentException(EXCHANGE_MANAGER_NOT_LOADED);
}
defaultService.AddService(service);
}
}
No comments yet. Be the first.
Leave a reply