private static async Task AsyncMain(Arguments args) { if (!String.IsNullOrEmpty(args.EncodedPayload)) { args.Payload = Encoding.UTF8.GetString(Convert.FromBase64String(args.EncodedPayload)); } if (!String.IsNullOrEmpty(args.EncodedConfiguration)) { args.Configuration = Encoding.UTF8.GetString(Convert.FromBase64String(args.EncodedConfiguration)); } var configuration = InvocationPayloadSerializer.Deserialize(args.Configuration); var service = await LocalWorkService.Create(configuration); var tcs = new TaskCompletionSource<object>(); string message = String.Format("Invoking job: {0}.", args.Job); Console.WriteLine(message); Console.WriteLine(new String('-', message.Length)); Stopwatch sw = new Stopwatch(); try { sw.Start(); var observable = service.RunJob(args.Job, args.Payload); observable .Subscribe( evt => RenderEvent(evt), ex => tcs.SetException(ex), () => tcs.SetResult(null)); await tcs.Task; sw.Stop(); } catch (AggregateException aex) { Console.Error.WriteLine(aex.InnerException.ToString()); } catch (Exception ex) { Console.Error.WriteLine(ex.ToString()); } message = String.Format("Completed invocation of job {0} in {1}.", args.Job, sw.Elapsed); Console.WriteLine(new String('-', message.Length)); Console.WriteLine(message); }