Job Scheduling in Asp.net: quartz.net

Source: Internet
Author: User

What do you do if you want to implement any functions similar to Windows in Asp.net?

You can write your method in the message so that I can learn and improve my program. Thank you.

The following is my method;

First download quartz.net

Add the following two parts to Web. config:

Code

<Configsections>
<! -- Quartz -->
<Section name = "quartz" type = "system. configuration. namevaluesectionhandler, system, version = 1.0.5000.0, culture = neutral, publickeytoken = b77a5c561934e089"/>
<! -- End Quartz -->
</Configsections>

 

 

Code

<! -- Start Quartz -->
<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>
<! -- End Quartz -->

 

 

Add the following fragments to global. asax:

 

Code

Void application_start (Object sender, eventargs E)
{

// SYS. log. SYS. Info ("Starting sched..."); // the start time of the log.
// Construct a scheduler Factory
Ischedulerfactory schedfact = new quartz. impl. stdschedulerfactory ();
// Get a scheduler
Sched = schedfact. getscheduler ();
Sched. Start ();

// Construct Job Info
Jobdetail = new jobdetail ("myjob", null, typeof (task. quartzjob_test ));
// Fire every hour
Trigger trigger = triggerutils. makesecondlytrigger (60*5 );
// Start on the next even hour
Trigger. starttimeutc = datetime. utcnow;
Trigger. Name = "mytrigger ";
Sched. schedulejob (jobdetail, trigger );

// Delay iispool
Task. delayiisthreadpool. url = httpcontext. Current. Request. url. tostring ();
Jobdetail jobdetail2 = new jobdetail ("myjob2", null, typeof (task. delayiisthreadpool ));
Trigger trigger2 = triggerutils. makesecondlytrigger (60*10 );
Trigger2.starttimeutc = datetime. utcnow;
Trigger2.name = "mytrigger2 ";
Sched. schedulejob (jobdetail2, trigger2 );
// End quartz
}

Void application_end (Object sender, eventargs E)
{
// Code that runs on application shutdown

// Quartz
If (sched! = NULL)
{
Sched. Shutdown (true );
}
// End quartz
}

 

 

Add the following two files to app_code:

 

Code

// Quartzjob_test.cs
Using system;
Using system. Collections. Generic;
Using system. Web;

Namespace task
{
/// <Summary>
/// Summary description for delayiisthreadpool
/// </Summary>
Public class delayiisthreadpool: quartz. ijob
{

# Region ijob members
Public static string URL;
Private Static system. net. WebClient WC = new system. net. WebClient ();

Public void execute (quartz. jobexecutioncontext context)
{
If (string. isnullorempty (URL ))
Return;
WC. downloadstring (URL );
}

# Endregion
}

}

 

 

Code

// Delayiisthreadpool. CS
Using system;
Using system. Collections. Generic;
Using system. Web;

Namespace task
{
Public class delayiisthreadpool: quartz. ijob
{

# Region ijob members
Public static string URL;
Private Static system. net. WebClient WC = new system. net. WebClient ();

Public void execute (quartz. jobexecutioncontext context)
{
If (string. isnullorempty (URL ))
Return;
WC. downloadstring (URL );
}

# Endregion
}

}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.