40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
using Learun.Loger;
|
||
using Quartz;
|
||
using System;
|
||
using System.Reflection;
|
||
|
||
namespace Learun.Application.Scheduler
|
||
{
|
||
public class DumbJob
|
||
{
|
||
private Log log = LogFactory.GetLogger("DumbJob");
|
||
public void Execute(IJobExecutionContext context)
|
||
{
|
||
try
|
||
{
|
||
JobKey key = context.JobDetail.Key;
|
||
JobDataMap dataMap = context.JobDetail.JobDataMap;
|
||
string taskClass = dataMap.GetString("taskClass");
|
||
|
||
// Load(命名空间名称),GetType(命名空间.类名)
|
||
Type type = Assembly.Load("Learun.Application.TwoDevelopment").
|
||
GetType(taskClass);
|
||
// GetMethod(需要调用的方法名称)
|
||
MethodInfo method = type.GetMethod("Execute");
|
||
// 调用的实例化方法(非静态方法)需要创建类型的一个实例
|
||
object obj = Activator.CreateInstance(type);
|
||
// 方法需要传入的参数
|
||
object[] parameters = new object[] { };
|
||
|
||
log.Info("开始执行任务【"+ key + "】!" + Environment.NewLine);
|
||
// 相应地调用静态方法时,Invoke的第一个参数为null
|
||
method.Invoke(obj, parameters);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
log.Error(ex);
|
||
}
|
||
}
|
||
}
|
||
}
|