static async Task MainAsync() { var job = new BackgroundJob(); job.ProgressUpdated += Job_ProgressUpdated; try { await job.Start(cts.Token); } catch (OperationCanceledException ex) { Console.WriteLine($"The job failed with an error: {ex}"); } }
static async Task MainAsync() { var job = new BackgroundJob(); var progress = new Progress <int>(Job_ProgressUpdated); try { await job.Start(progress); } catch (Exception ex) { //now your exception is caught Console.WriteLine($"The job failed with an error: {ex}"); } }
protected override void OnStart(string[] args) { base.OnStart(args); Thread workerThread = new Thread(() => { _backgroundJob = new BackgroundJob(_dependencies); _backgroundJob.Start().Wait(); }); workerThread.Start(); }