这是安排输出任务的主要步骤
Public Sub ScheduleOutput()
Dim sf As ISchedulerFactory = New StdSchedulerFactory()
Dim scheduler As IScheduler = sf.GetScheduler()
scheduler.Start()
Dim job As IJobDetail = JobBuilder.Create(Of OutputJob)().
WithIdentity("output", "output").Build()
Dim trigger As ITrigger = TriggerBuilder.Create().
WithIdentity("trigger", "trigger").ForJob("output").
WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(setHour.Text, setMinute.Text)).
Build()
MsgBox("end")
End Sub
和工作类别
Public Class OutputJob
Implements IJob
Public Sub Execute(context As IJobExecutionContext) Implements IJob.Execute
Output()
End Sub
Public Sub Output()
Dim b = Convert.FromBase64String(HttpContext.Current.Request.Form("encodedhtml"))
Dim html = System.Text.Encoding.UTF8.GetString(b)
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "text/html"
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=""Dashboard.html""")
HttpContext.Current.Response.Write(html)
HttpContext.Current.Response.End()
End Sub
End Class
Web.config文件
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">
<arg key="configType" value="INLINE"/>
<arg key="configFile" value="~/log4net.config"/>
<arg key="level" value="INFO" />
</factoryAdapter>
</logging>
</common>
<log4net>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %l - %m%n" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="EventLogAppender" />
</root>
</log4net>
</configuration>
当我尝试运行代码时,Dim sf As ISchedulerFactory = New StdSchedulerFactory()
发生了异常
something.dll中发生了'System.TypeInitializationException'类型的异常,但未在用户代码中处理
其他信息:“ Quartz.Impl.StdSchedulerFactory”的类型初始值设定项引发了异常。
输出中的异常消息(显示在Visual Studio的底部):
类型的第一次机会异常 Common.Logging.dll中发生了'Common.Logging.ConfigurationException' 类型为“ System.TypeInitializationException”的第一次机会异常 发生在something.dll
如何解决该异常?
以及代码中可能导致错误/异常的其他任何部分?
我为此一直苦苦挣扎,并寻找了很多解决方案,但是它们都无法真正帮助我(或者只是我不知道如何修改才能适合我的代码),因为我确实缺乏知识有关任务计划和配置设置。
答案 0 :(得分:0)
Quartz仅依赖于一个称为Common.Logging的第三方库(该库包含允许您使用最适合您的日志记录提供程序的日志记录抽象)。您必须在应用程序二进制文件旁边具有Quartz.dll,Commong.Logging.dll和Commong.Logging.Core.dll,才能成功运行Quartz.NET
并将Common.Logging.Log4Net1213.dll部分替换为:
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">
<arg key="configType" value="INLINE"/>
<arg key="level" value="INFO" />
</factoryAdapter>
</logging>
</common>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.3.1.0" newVersion="3.3.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>