我的代码适用于表单应用程序,但相同的代码不适用于Windows服务!
protected override void OnStart(string[] args)
{
try
{
// First we must get a reference to a scheduler
ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sched = sf.GetScheduler();
// get a "nice round" time a few seconds in the future...
DateTimeOffset startTime = DateBuilder.NextGivenSecondDate(null, 15);
// job1 will only fire once at date/time "ts"
IJobDetail job = JobBuilder.Create<SimpleJob>()
.WithIdentity("job1", "group1")
.Build();
ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.StartAt(startTime)
.WithSimpleSchedule(x => x.WithIntervalInSeconds(60).RepeatForever())
.Build();
// Tell quartz to schedule the job using our trigger
sched.ScheduleJob(job, trigger);
// Start up the scheduler (nothing can actually run until the
// scheduler has been started)
sched.Start();
}
catch (Exception x)
{
Operation.Logger.Error("Servis başlatma hatası: "+x.StackTrace);
}
}
public class SimpleJob : IJob
{
bool inProgress = false;
public virtual void Execute(IJobExecutionContext context)
{
if (!inProgress)
{
try
{
inProgress = true;
Incoming incomingFiles = new Incoming();
incomingFiles.Start();
Outgoing outgoingFiles = new Outgoing();
outgoingFiles.Start();
inProgress = false;
}
catch (Exception x)
{
Operation.Logger.Error("f8job çalışma hatası: "+ x.Message);
inProgress = false;
}
}
}
}
System.IO.FileNotFoundException: Could not load file or assembly 'Common.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e' or one of its dependencies. The system cannot find the file specified.
File name: 'Common.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e'
at Quartz.Impl.StdSchedulerFactory..cctor()
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].