public void Execute(IJobExecutionContext context) { string className = context.JobDetail.JobDataMap.Get(Consts.JobClassName).ToString(); string assemblyPath = context.JobDetail.JobDataMap.Get(Consts.JobAssemblyPath).ToString(); try { Assembly assembly = Consts.GetAssembly(assemblyPath); BaseJob job = assembly.CreateInstance(className) as BaseJob; object p = context.JobDetail.JobDataMap.Get(Consts.JobParameter); string ps = p == null ? string.Empty : p.ToString(); job.Execute(ps); WriteJobLog((JobDetailImpl)context.JobDetail); } catch (Exception ex) { Exception wrapper = new Exception(string.Format("Job异常, assembly:{0}; class:{1}", assemblyPath, className), ex); // LogManager.LogException(wrapper); WriteJobLog((JobDetailImpl)context.JobDetail, ex); } }
public Task ExecuteJob(BaseJob baseJob) //async { ProcessJob = baseJob; StopWatch.Start(); Progress <string> progress = new Progress <string>(print); Task task = Task.Run(() => { //await baseJob.Execute(progress, CancellationToken.None); }); task.Wait(); StopWatch.Stop(); ProcessJob.ExecutionTime = StopWatch.Elapsed.Ticks; JobDone?.Invoke(this, ProcessJob); ProcessJob = null; return(task); }