0

我的代码在表单应用程序上运行良好,但相同的代码在 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].
4

1 回答 1

0

尝试将您的服务配置为在您的代码正常运行的 Windows 帐户中运行。

于 2012-11-28T14:01:45.840 回答