Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Here is the main procedure for scheduling an output task
VB
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

and the job class
VB
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 file
XML
<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>

When I try to run the code, an exception occurred in Dim sf As ISchedulerFactory = New StdSchedulerFactory()
Quote:
An exception of type 'System.TypeInitializationException' occurred in something.dll but was not handled in user codeAdditional information: The type initializer for 'Quartz.Impl.StdSchedulerFactory' threw an exception.

Exception messages in the Output (shown at the bottom of Visual Studio):
Quote:
A first chance exception of type 'Common.Logging.ConfigurationException' occurred in Common.Logging.dll
A first chance exception of type 'System.TypeInitializationException' occurred in something.dll

How can I fix the exception?
And any other parts in the code that can cause errors/exceptions?

What I have tried:

I have struggled for long about this and have searched for a lot of solutions, but none of them can actually help me (or just I don't know how to modify in order to fit my code) because I really lack knowledge about task scheduling and configuration settings.
Posted
Updated 21-May-19 8:27am
Comments
[no name] 20-May-19 23:47pm    
What is "something.dll". It appears that's where the problem is. It's choking on "something". Do you know what "something" does? You think someone else knows something?
Ursidae4518 21-May-19 5:46am    
You can suppose that is just an application content related file. It was neither created nor modified by me, and it is not even included in any of the code. I'm more concerned about how to handle with common.logging and configuration settings to utilise Quartz.NET.

1 solution

Quote:
because I really lack knowledge about task scheduling and configuration settings.


What version of Quartz.Net and ASP.NET you were using? Quartz.Net has a website that provides a comprehensive documentation about its usage here: Quartz Enterprise Scheduler .NET | Quartz.NET Documentation[^]

Just select the version that you were using and then navigate to its corresponding documentation. If you are new to it, then start with just a simple scheduling by following the example. You need to test out first if it works, so start with the simple one. Once you are able to make the simple scheduling work, then start modifying it based on your needs by following the documentation.

Here's an excellent article that you can also refer to get started: Scheduled Tasks In ASP.NET With Quartz.Net[^]
 
Share this answer
 
Comments
Ursidae4518 22-May-19 6:30am    
The versions of Quartz.NET and ASP.NET are 2.6.2 and 4.8.03761 respectively (At first I downloaded the newest release of Quartz.NET but it seemed unavailable with the version of ASP.NET/Visual Studio so I downloaded an older one then).
I have looked into the official documentation. That's actually one of the source where I referred to when I build the above code. However, exceptions and errors occurred so I realise if it can really fit into what I'm working on.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900