private void RunJob(TriggeredJob jobtype, TraceWriter logger, CancellationToken cancellationToken) { using (var thisContainer = ServiceLocator.CreateNestedContainer()) { logger.Info($"found job type {jobtype.FullName}"); try { var job = thisContainer.GetInstance(jobtype.ContainingClass); logger.Verbose($"Obtained instance of type {jobtype.FullName} from IoC"); var methodParamValues = BuildParams(jobtype, logger, cancellationToken); jobtype.InvokedMethod.Invoke(job, methodParamValues); Task.Run(() => jobtype.InvokedMethod.Invoke(job, methodParamValues)) .ContinueWith(task => { logger.Info($"Job has ended. Cancelled?:{task.IsCanceled} Faulted?:{task.IsFaulted}"); if (task.IsFaulted) { logger.Error($"Exception: {task.Exception}"); } }); } catch (Exception e) { logger.Error($"Failed to fetch and execute instance of type {jobtype.FullName} from IoC - error: {e.GetType()} - {e.Message}"); throw; } } }