当铺网,泽惠希,追忆骑士2.0
从源码中找到“corebackgroundjobperformer”执行任务的方法
internal class corebackgroundjobperformer : ibackgroundjobperformer { private readonly jobactivator _activator; //ioc容器 ....省略 //执行任务 public object perform(performcontext context) { //创建一个生命周期 using (var scope = _activator.beginscope( new jobactivatorcontext(context.connection, context.backgroundjob, context.cancellationtoken))) { object instance = null; if (context.backgroundjob.job == null) { throw new invalidoperationexception("can't perform a background job with a null job."); } //任务是否为静态方法,若是静态方法需要从ioc容器中取出实例 if (!context.backgroundjob.job.method.isstatic) { instance = scope.resolve(context.backgroundjob.job.type); if (instance == null) { throw new invalidoperationexception( $"jobactivator returned null instance of the '{context.backgroundjob.job.type}' type."); } } var arguments = substitutearguments(context); var result = invokemethod(context, instance, arguments); return result; } } //调用方法 private static object invokemethod(performcontext context, object instance, object[] arguments) { try { var methodinfo = context.backgroundjob.job.method; var result = methodinfo.invoke(instance, arguments);//使用反射调用方法 ....省略 return result; } ....省略 } }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论