0
如果我使用XML定義對象並調用var xmlApplicationContext = new XmlApplicationContext()
,那麼該作業將被調度並觸發。我想要完成的是通過代碼來完成此操作,因爲屬性是動態的,下面的方法片段編譯並運行,但作業未安排。這可能嗎?Spring.Net編程與XML配置
// SpringJob.xml
<objects xmlns="http://www.springframework.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<object name="emailNotification" type="Spring.Scheduling.Quartz.JobDetailObject, Spring.Scheduling.Quartz">
<property name="JobType" value="Project.Agent.Jobs.EmailNotification, Project.Agent" />
</object>
<object id="simpleTrigger" type="Spring.Scheduling.Quartz.SimpleTriggerObject, Spring.Scheduling.Quartz">
<property name="jobDetail" ref="emailNotification" />
<property name="startDelay" value="1s" />
<property name="repeatInterval" value="1s" />
<property name="repeatCount" value="0" />
</object>
<object type="Spring.Scheduling.Quartz.SchedulerFactoryObject, Spring.Scheduling.Quartz">
<property name="triggers">
<list>
<ref object="simpleTrigger" />
</list>
</property>
</object>
</objects>
//方法
var jobDetailObject = new JobDetailObject
{
JobType = new EmailNotification().GetType()
};
var simpleTrigger = new SimpleTriggerObject
{
JobDetail = jobDetailObject,
StartDelay = new TimeSpan(0, 0, 0, 1),
RepeatInterval = new TimeSpan(0, 0, 0, 1),
RepeatCount = 0
};
var scheduleTrigger = new SchedulerFactoryObject();
var triggers = new Trigger[1];
triggers[0] = simpleTrigger;
scheduleTrigger.Triggers = triggers;
scheduleTrigger.Start();