/// <summary> /// Run Async /// </summary> /// <returns>Task</returns> public virtual async Task RunAsync() { var timing = Stopwatch.StartNew(); var type = this.GetType(); var startTime = DateTime.UtcNow; var successful = false; Trace.TraceInformation("{0}: Task Checking.", base.Name); try { var ready = await coordinator.Check(type); if (ready) { Trace.TraceInformation("{0}: Task Starting.", base.Name); var identifier = Guid.NewGuid(); await this.coordinator.Start(type, identifier, startTime); try { this.Run(); successful = true; } catch (Exception ex) { Trace.TraceError("{0}: {1}", base.Name, ex.ToString()); successful = false; } await this.coordinator.Complete(type, identifier, startTime, DateTime.UtcNow, successful); } else { Trace.TraceInformation("{0}: Task not Started.", base.Name); } } catch (Exception ex) { Trace.TraceError("{0}: {1}", base.Name, ex.ToString()); successful = false; } finally { timing.Stop(); } Trace.TraceInformation("{0}: Coordinated Task Completed (Duration: {1}).", base.Name, timing.Elapsed); }