For those of you that are creating custom forms and custom task handlers as described in some of these previous posts…
… Patrik Sundqvist has written a great blog post about how to use the debugger to investigate issues. Check it out!
This same process should also work for debugging workflows, but in that case you will want to attach the debugger to the right monitoringhost.exe on the Service Manager management server. Note – there can be more than one monitoringhost.exe process running at the same time – typically when the workflows are running in a different security context (i.e. user) so make sure you attach the debugger to the right one!
I learned an excellent trick from the devs today how to debug workflows. Here’s the deal….
If you simply open up Task Manager and attach to one of the MonitoringHost.exe processes there it is probably the wrong one. You would probably be attaching to the system MonitoringHost.exe workflow process that is essentially always running and it is typically not the MonitoringHost.exe process which is actually running your workflow. Typically, the MonitoringHost.exe process that is running your workflow will only appear in the task manager for a split second if at all because the workflows typically run so fast. So – you basically need to slow down the workflow temporarily when you are debugging so that you have time to see the MonitoringHost.exe process show up in Task Manager and can attach the debugger to it.
I’d suggest adding a Thread.Sleep(10000) to your code. You can even put it in an infinite while loop so you have plenty of time to look for the new MonitoringHost.exe process to show up in Task Manager and attach the debugger to it.
I think you could also try System.Diagnostics.Debugger.Launch() from managed code in your custom form or workflow :)