40 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}
}
}