static void DoWork(object state) { if (state == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("state"); } AsyncCallbackState callbackState = (AsyncCallbackState)state; bool executingWork = false; try { //If SyncContext is enabled //We have to do another post to get to correct thread. if (callbackState.SynchronizationContext != null) { SynchronizationContext synchronizationContext = callbackState.SynchronizationContext; callbackState.SynchronizationContext = null; SynchronizationContextWorkflowSchedulerService.SynchronizationContextPostHelper.Post( synchronizationContext, WorkflowOperationAsyncResult.sendOrPostCallback, callbackState); } else //We are in correct thread to do the work. { using (new WorkflowDispatchContext(true)) { callbackState.WorkflowRequestContext.SetOperationBegin(); executingWork = true; if (callbackState.WorkflowInstanceLifeTimeManager != null) { callbackState.WorkflowInstanceLifeTimeManager.NotifyMessageArrived(callbackState.WorkflowInstance.InstanceId); } callbackState.WorkflowInstance.EnqueueItemOnIdle( callbackState.QueueName, callbackState.WorkflowRequestContext, null, null); } } } catch (QueueException e) { WorkflowOperationFault operationFault = new WorkflowOperationFault(e.ErrorCode); try { if (callbackState.WorkflowInstanceLifeTimeManager != null) { callbackState.WorkflowInstanceLifeTimeManager.ScheduleTimer(callbackState.WorkflowInstance.InstanceId); } callbackState.WorkflowRequestContext.SendFault(new FaultException(operationFault), null); } catch (Exception unhandled) { if (Fx.IsFatal(unhandled)) { throw; } // ignore exception; we made best effort to propagate the exception back to the invoker thread } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } try { if (callbackState.WorkflowInstanceLifeTimeManager != null) { callbackState.WorkflowInstanceLifeTimeManager.ScheduleTimer(callbackState.WorkflowInstance.InstanceId); } //We should field only user code exception; Everything else should go abort path. callbackState.WorkflowRequestContext.GetAsyncResult().SendFault(e, null); } catch (Exception e1) { if (Fx.IsFatal(e1)) { throw; } // ignore exception; we made best effort to propagate the exception back to the invoker thread } } finally { try { if (executingWork) { callbackState.WorkflowRequestContext.SetOperationCompleted(); } } catch (Exception e1) { if (Fx.IsFatal(e1)) { throw; } // ignore exception; we made best effort to propagate the exception back to the invoker thread } } } }
static void DoWork(object state) { if (state == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("state"); } AsyncCallbackState callbackState = (AsyncCallbackState) state; bool executingWork = false; try { //If SyncContext is enabled //We have to do another post to get to correct thread. if (callbackState.SynchronizationContext != null) { SynchronizationContext synchronizationContext = callbackState.SynchronizationContext; callbackState.SynchronizationContext = null; SynchronizationContextWorkflowSchedulerService.SynchronizationContextPostHelper.Post( synchronizationContext, WorkflowOperationAsyncResult.sendOrPostCallback, callbackState); } else //We are in correct thread to do the work. { using (new WorkflowDispatchContext(true)) { callbackState.WorkflowRequestContext.SetOperationBegin(); executingWork = true; if (callbackState.WorkflowInstanceLifeTimeManager != null) { callbackState.WorkflowInstanceLifeTimeManager.NotifyMessageArrived(callbackState.WorkflowInstance.InstanceId); } callbackState.WorkflowInstance.EnqueueItemOnIdle( callbackState.QueueName, callbackState.WorkflowRequestContext, null, null); } } } catch (QueueException e) { WorkflowOperationFault operationFault = new WorkflowOperationFault(e.ErrorCode); try { if (callbackState.WorkflowInstanceLifeTimeManager != null) { callbackState.WorkflowInstanceLifeTimeManager.ScheduleTimer(callbackState.WorkflowInstance.InstanceId); } callbackState.WorkflowRequestContext.SendFault(new FaultException(operationFault), null); } catch (Exception unhandled) { if (Fx.IsFatal(unhandled)) { throw; } // ignore exception; we made best effort to propagate the exception back to the invoker thread } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } try { if (callbackState.WorkflowInstanceLifeTimeManager != null) { callbackState.WorkflowInstanceLifeTimeManager.ScheduleTimer(callbackState.WorkflowInstance.InstanceId); } //We should field only user code exception; Everything else should go abort path. callbackState.WorkflowRequestContext.GetAsyncResult().SendFault(e, null); } catch (Exception e1) { if (Fx.IsFatal(e1)) { throw; } // ignore exception; we made best effort to propagate the exception back to the invoker thread } } finally { try { if (executingWork) { callbackState.WorkflowRequestContext.SetOperationCompleted(); } } catch (Exception e1) { if (Fx.IsFatal(e1)) { throw; } // ignore exception; we made best effort to propagate the exception back to the invoker thread } } } }