protected override void Execute(NativeActivityContext context) { ReceiveRequestSendResponseScopeExecutionProperty executionProperty = context.GetReceiveRequestSendResponseScopeExecutionProperty(); if (!executionProperty.Faulted && !executionProperty.IsInitializedAndCompleted) { // The taskCompletionSource from an incoming request is not completed (we don't have it or we have but not completed). if (!executionProperty.IsInitializedButNotCompleted) { // We don't have taskCompletionSource from an incoming request. if (executionProperty.Idempotent && context.GetPreviousResponseParameterExtension().TrySetResponseCanceled(executionProperty.OperationName)) { context.ScheduleActivity(persist); } } else { // We have taskCompletionSource from an incoming request, after setting the response in the extension we cancel the taskCompletionSource also. if (executionProperty.Idempotent && context.GetPreviousResponseParameterExtension().TrySetResponseCanceled(executionProperty.OperationName)) { context.ScheduleActivity(persist, PersistCompletionCallback); } else { executionProperty.TrySetTaskCompletionSourceCanceled(); } } } }