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
}
}