Click or drag to resize

Fourth Attempt, Synchronous Call

What happens when we call the ExecuteAsync method? This is an asynchronous method, so when we call it in the "fire & forget" fashion like we did in the prior attempts, the unfortunate answer is that "there is no way to know when the method completed or what was the outcome of its execution". What can we do in order to call the asynchronous method in a more controlled way?

The simplest answer is to wait for completion of the method by blocking our thread of execution.

Sync Over Async

The ExecuteAsync method, being a "well-behaved" asynchronous method returns a Task, or more specifically a Task<ProcessResult>. This makes it possible to wait until the method completes and then evaluate the result. In this fourth attempt, we synchronously wait for the method completion by accessing the Result property of the returned Task. The current thread is blocked while waiting, however once the wait is over, we are rewarded with the results of the completed process.

using Mavidian.DataConveyer;
using Mavidian.DataConveyer.Orchestrators;
var config = new OrchestratorConfig()
  InputDataKind = KindOfTextData.Delimited,
  InputFileName = "input.csv",
  HeadersInFirstInputRow = true,
  OutputDataKind = KindOfTextData.Keyword,
  OutputFileName = ""
ProcessResult rslt;
using (var orchtr = OrchestratorCreator.GetEtlOrchestrator(config))
  rslt = orchtr.ExecuteAsync().Result;
if (rslt.CompletionStatus == CompletionStatus.IntakeDepleted)
  Console.WriteLine($"Successfully converted {rslt.RowsWritten} records!");
See Also