C# 클래스 Brass9.Threading.IntervalTask

For ASP.Net applications. Starts a thread to perform a task at BelowNormal priority on a regular interval. Meant for long-running ASP.Net apps that never recycle instead of a Windows Service or cron job. If the task runs longer than the timer interval, the existing thread is left be and nothing else happens until the next time the interval fires where the worker thread is not running. Cannot handle multiple tasks; if you have multiple tasks to manage, build on top of this class by adding task registration to a single task that this class runs. The task is defined as an Action<IntervalTaskContext>, where the argument it takes is a context object that has a single property: Stopping. If the ASP.Net app needs to shut down for some reason, and the task is currently running, this flag will flip to true, and the app will be forcibly torn down by the environment in 30 seconds. This means the task should check Stopping regularly to see if it should cut its work short. Note that the 30 seconds is for the entire app to tie up what it's doing, not just this task - so be conservative. For more on the ASP.Net App teardown process: http://msdn.microsoft.com/en-us/library/system.web.hosting.iregisteredobject.stop.aspx http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx
상속: System.Web.Hosting.IRegisteredObject, IDisposable
파일 보기 프로젝트 열기: b9chris/ASP.Net-Long-Running-Interval-Task 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
intervalTimer TimerInfo
taskAction System.Action
taskThread Thread

공개 메소드들

메소드 설명
CreateTask ( System.Action taskAction ) : IntervalTask

Creates a new IntervalTask (and doesn't run it - call SetTimerInterval() to start it). taskAction format: context => { /* do work */ } If a task has already been created, throws a FieldAccessException.

Dispose ( ) : void

Stops the Timer, and informs the ASP.Net hosting environment that it doesn't need to wait on the IntervalTask to shut down.

SetInterval ( int interval ) : void

If the background task timer is running, changes its interval. If the timer isn't running, starts the timer (and so, the background task).

Stop ( bool immediate ) : void

Call if the app is shutting down. Should only be called by the ASP.Net container.

StopTimer ( ) : void

Stops the timer. If the background task is running when this is called, it's left be so it can finish it's work, but will not be woken up to start again until SetTimerInterval() is called with a positive value. Convenience method. This has the same effect as calling SetTimerInterval(Timeout.Infinite);

보호된 메소드들

메소드 설명
IntervalTask ( System.Action taskAction ) : System
intervalCallback ( ) : void
taskActionWrapper ( ) : void

메소드 상세

CreateTask() 공개 정적인 메소드

Creates a new IntervalTask (and doesn't run it - call SetTimerInterval() to start it). taskAction format: context => { /* do work */ } If a task has already been created, throws a FieldAccessException.
public static CreateTask ( System.Action taskAction ) : IntervalTask
taskAction System.Action An Action to be run on an interval
리턴 IntervalTask

Dispose() 공개 메소드

Stops the Timer, and informs the ASP.Net hosting environment that it doesn't need to wait on the IntervalTask to shut down.
public Dispose ( ) : void
리턴 void

IntervalTask() 보호된 메소드

protected IntervalTask ( System.Action taskAction ) : System
taskAction System.Action
리턴 System

SetInterval() 공개 메소드

If the background task timer is running, changes its interval. If the timer isn't running, starts the timer (and so, the background task).
public SetInterval ( int interval ) : void
interval int The timer interval in milliseconds.
리턴 void

Stop() 공개 메소드

Call if the app is shutting down. Should only be called by the ASP.Net container.
public Stop ( bool immediate ) : void
immediate bool ASP.Net sets this to false first, then to true the second /// call 30 seconds later.
리턴 void

StopTimer() 공개 메소드

Stops the timer. If the background task is running when this is called, it's left be so it can finish it's work, but will not be woken up to start again until SetTimerInterval() is called with a positive value. Convenience method. This has the same effect as calling SetTimerInterval(Timeout.Infinite);
public StopTimer ( ) : void
리턴 void

intervalCallback() 보호된 메소드

protected intervalCallback ( ) : void
리턴 void

taskActionWrapper() 보호된 메소드

protected taskActionWrapper ( ) : void
리턴 void

프로퍼티 상세

intervalTimer 보호되어 있는 프로퍼티

protected TimerInfo,Brass9.Threading intervalTimer
리턴 TimerInfo

taskAction 보호되어 있는 프로퍼티

protected Action,System taskAction
리턴 System.Action

taskThread 보호되어 있는 프로퍼티

protected Thread taskThread
리턴 Thread