2

我有一个调用quartz.net 的Windows 服务,如下所示:

  ISchedulerFactory schedFact = new StdSchedulerFactory();
  sched = schedFact.GetScheduler();
  sched.Start();

我的配置文件如下:

<add key="quartz.plugin.xml.fileNames" value="~/quartz/quartz_jobs.xml" />

在发布我的 Windows 服务时,我设计了以下文件夹结构:

/bin/      "Various Dlls for my windows service"
/bin/Quartz/    "Includes by schedule plugins ( Seperate classes and my Jobs file )

我遇到的问题是,quartz 找不到我的程序集,除非我将它们复制到 /bin/ 的根目录中。

有什么想法可以将所有计划程序集保存在单独的文件夹中吗?

4

1 回答 1

2

感谢 Google 小组的 Karell。

这是我解决这个问题的代码。

   AppDomain currentDomain = AppDomain.CurrentDomain;
   currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);


 private Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
        {

            Assembly MyAssembly,objExecutingAssemblies = Assembly.GetExecutingAssembly();
            AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies();
            if(args.Name.Contains("Coyname.Product.Service.Scheduler"))
            {
                string assName = Parser.ParseAssemblyNameReference(args.Name);
                var rootDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var pluginDir = Path.Combine(rootDirectory, "Quartz");
                pluginDir += string.Format("\\{0}.dll",assName);;
                MyAssembly =  Assembly.LoadFrom(pluginDir); 
            }
            else
            {
                MyAssembly = Assembly.LoadFrom(string.Empty); 
            }
            return MyAssembly;
}
于 2012-07-09T21:05:00.130 回答