I've got common code that can run in a number of execution enviroments - within IIS, within a WCF service, in a stand-alone application, or in a Windows Workflow instance.
But what is the best way to check whether the code is running inside a Workflow? For the moment, I've been looking for WorkflowEnvironment.WorkflowInstanceID
and catching any exceptions with this code:
...
try
{
if (WorkflowEnvironment.WorkflowInstanceId != null)
{
return ExecutionContext.Workflow;
}
}
catch
{
}
// return unknown
return ExecutionContext.Unknown;
Isn't there a better way? I want to remove the need for a try...catch
block.