Problems in getting workflows up and running? Workflows hanging in the middle of execution? Workflows throwing unexpected exceptions? Here are some troubleshooting tips to know what is happening there and what is NOT happening.
1. Regsiter to the events on WorkflowRuntime in host. WorkflowRuntime class exposes events like workflowterminated, workflowcompleted, workflowaborted etc. Subscribing to these events will help you to understand what is happening to the workflow instance.2. Trace workflow execution. Add the following config file in your host (version > 4008). This will trace the entire workflow execution in the specified file.
<configuration><system.diagnostics> <switches> <add name="System.Workflow LogToTraceListeners" value="1" />
<add name="System.Workflow.Runtime.Hosting" value="All" />
<add name="System.Workflow.Runtime" value="All" />
<add name="System.Workflow.Runtime.Tracking" value="All" />
<add name="System.Workflow.Activities" value="All" />
</switches> <trace autoflush="true" indentsize="4"> <listeners> <add name="customListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="WFTrace.log" /> </listeners> </trace></system.diagnostics></configuration>
3. Debug!. Workflow debugger is useful and user friendly tool to step through the execution of workflows. To set breakpoint, open the designer view, select an activity and press F9. Mark the workflow project as the start up and start debugging using F5. You can use F10, F11, Shift + F11 to step through the activities and code beside of the workflow. Debugging workflows is itself a big topic. I will be posting more information about it in this blog. Keep watching.