ASP. Net scheduled task execution, ASP. Net task execution

Source: Internet
Author: User
Tags net thread

ASP. Net scheduled task execution, ASP. Net task execution

Raw materials:

System. timers. timer (): Pass. NET Thread Pool is lightweight, accurate timing, and has no special requirements on applications and messages. The disadvantage is that it does not support direct drag and drop and requires manual encoding.

Main attributes of Timer:

1. Interval: Interval at which Elapsed events are triggered;

2. Elapsed: events that occur at intervals;

3. Enabled: Indicates whether Timer should trigger the Elapsed event;

Design:

I. TaskBase: Task Base Class

1. Field:

A. TimeMode. The task types include cycle and time;

B. LastStartTime

2. attributes:

A. NextStartTime, read-only attribute

If (this. TimeMode = 0)
{
If (this. LastStartTime = DateTime. MinValue)
{
Return DateTime. MinValue;
}
Return this. LastStartTime. AddSeconds (double) this. MinPeriod );
}
If (this. LastStartTime = DateTime. MinValue)
{
Return this. TheFixedNextStartTime;
}
Return this. LastStartTime. AddDays (1.0). Date. AddHours (double) this. Hour). AddMinutes (double) this. Minute );

B. TheFixedNextStartTime; read-only attribute

If (this. _ theFixedNextStartTime = DateTime. MinValue)
{
This. _ theFixedNextStartTime = DateTime. Today. AddHours (double) this. Hour). AddMinutes (double) this. Minute );
If (SystemStartTime. Hour * 100) + SystemStartTime. Minute)> (this. Hour * 100) + this. Minute ))
{
This. _ theFixedNextStartTime = this. _ theFixedNextStartTime. AddDays (1.0 );
}
}
Return this. _ theFixedNextStartTime;

3. Method:

1. Execute: Specific execution of a task

2. Run: Run the task.

This. LastStartTime = DateTime. Now;

This. Execute ();

Ii. TaskMonitor: Job monitoring

1. Method

A. Execute: Timer. Elapsed event

If (TimeMode = 1)
{
Flag = DateTime. Now> = base2.NextStartTime;
}
Else
{
Flag = (base2.TickCount = 0) & (base2.LastStartTime = DateTime. MinValue ));
If (! Flag)
{// Comparison of the timer running interval and task running Interval
Base2.TickCount + = CheckPeriod;
Flag = base2.TickCount> = base2.MinPeriod;
}
If (flag)
{
Base2.TickCount = 0;
}
}
If (flag)
Thread. RunMethod (new ThreadStart (base2.Run ));

      

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.