Dot Net Tips and Tricks

Custom Search

Archive for March, 2007

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

Windows Workflow Call External Method and IClonable

Here’s a little gotcha that Microsoft put in Windows Workflow Foundation.

The CallExternalMethod activity is defined as

Defines a workflow communication activity that is used to call a method on a local service. This activity is used to send data from the workflow to the host through the local service.

You select the interface of the service where the method exists and then select the method name. The designer automatically creates properties that correspond to the parameters of the method to call. You can then double-click the little blue “Bind Property” tag in the property window. This allows you to bind the property to any member in the workflow of the same type. This all seems great, until you use it at runtime. What Microsoft fails to state is if the object you bind to impliments IClonable, at execution time, the object will be Cloned then passed to the service’s method. Noware else can I find where an object is Cloned prior to being passed.

I’m still struggling to find the reason for this one, but it’s a gotcha for sure since the documentation states nothing about it.

1 comment

File Tracing in Windows Workflow Foundation

After fighting with the windows workflow (WWF) runtime for a few hours, I finally found and article in the WIKI that showed the tracing switches changed in the released version.

The following will log everything to a file on the computer where the runtime is located:

<system.diagnostics>
<switches>
<add name=”System.Workflow LogToTraceListeners” value=”1″ />
<add name=”System.Workflow.Runtime.Hosting” value=”Verbose” />
<add name=”System.Workflow.Runtime” value=”Verbose” />
<add name=”System.Workflow.Runtime.Tracking” value=”Verbose” />
<add name=”System.Workflow.Activities” value=”Verbose” />
<add name=”System.Workflow.Activities.Rules” value=”Verbose” />
</switches>
<trace autoflush=”true” indentsize=”4″>
<listeners>
<add name=”myListener”
type=”System.Diagnostics.TextWriterTraceListener”
initializeData=”D:\Remoting\TextWriterOutput.log” />
</listeners>
</trace>
</system.diagnostics>

And contrary to most of the postings on the internet, this is current for the RTM release of Windows Workflow Foundation.

No comments