QuartzIs a Java open-source job scheduling framework. Http://www.opensymphony.com/quartz/
There is an easy-to-understand article on the IBM websiteArticle: Http://www.ibm.com/developerworks/cn/java/j-quartz/
Quartz.net is ported from Java to. net. Http://quartznet.sourceforge.net/
I have found many tutorials online, but none of them are about how to use them in ASP. NET.Code. Since it applies to any. netProgramOf course, this applies to Asp.net web applications.
(1) perform related configuration in Web. config
<Configsections>
<Section name = "quartz" type = "system. configuration. namevaluesectionhandler, system, version = 1.0.5000.0, culture = neutral, publickeytoken = b77a5c561934e089"/>
<Sectiongroup name = "common">
<Section name = "logging" type = "common. Logging. configurationsectionhandler, common. Logging"/>
</Sectiongroup>
</Configsections>
<Common>
<Logging>
<Factoryadapter type = "common. Logging. Simple. consoleoutloggerfactoryadapter, common. Logging">
<Arg key = "showlogname" value = "true"/>
<Arg key = "showdatatime" value = "true"/>
<Arg key = "level" value = "debug"/>
<Arg key = "datetimeformat" value = "HH: mm: SS: fff"/>
</Factoryadapter>
</Logging>
</Common>
<Quartz>
<Add key = "quartz. scheduler. instancename" value = "exampledefaultquartzscheduler"/>
<Add key = "quartz. threadpool. Type" value = "quartz. simpl. simplethreadpool, quartz"/>
<Add key = "quartz. threadpool. threadcount" value = "10"/>
<Add key = "quartz. threadpool. threadpriority" value = "2"/>
<Add key = "quartz. jobstore. misfirethreshold" value = "60000" type = "codeph" text = "/codeph"/>
<Add key = "quartz. jobstore. Type" value = "quartz. simpl. ramjobstore, quartz"/>
</Quartz>
In addition, I added a configuration item: <etettings>
<Add key = "cronexpr" value = "0 0 8-17/1? * 2-6 "/>
</Appsettings>
(2) create a common class to implement the quartz. ijob Interface Public class retrieveaj2003t140job: quartz. ijob
{< br> Private Static dataview aj2003view;
Public retrieveaj2003t140job ()
{< br> //
// todo: add the constructor logic here
//
}
Public void execute (quartz. jobexecutioncontext context)
{< br> // throw new exception ("the method or operation is not implemented. ");
// your processing logic, that is," work "
}
The interface is very simple. You only need to perform logical processing in the execute () method. For example, reading database data or reading emails.
(3) start the job scheduling in the global. asax File
This allows us to start job scheduling when the web application is started.
<% @ Import namespace = "quartz" %>
<SCRIPT runat = "server">
Ischeduler sched;
Void application_start (Object sender, eventargs E)
{
// Code that runs when the application starts
Ischedulerfactory Sf = new quartz. impl. stdschedulerfactory ();
Sched = SF. getscheduler ();
Jobdetail job = new jobdetail ("job1", "group1", typeof (retrieveaj2003t140job ));
String cronexpr = configurationmanager. etettings ["cronexpr"];
Crontrigger trigger = new crontrigger ("trigger1", "group1", "job1", "group1", cronexpr );
Sched. addjob (job, true );
Datetime Ft = sched. schedulejob (trigger );
Sched. Start ();
}
Void application_end (Object sender, eventargs E)
{
// Code that runs when the application is closed
If (sched! = NULL)
{
Sched. Shutdown (true );
}
}
</SCRIPT>
It should be noted that when application_end is used, quartz should be disabled.
OK. It can be used normally in ASP. NET.