Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
777 views
in Technique[技术] by (71.8m points)

c# - Execute method in global.asax every few minutes

What is the most effective way to execute a method in the Global.asax file every x number of minutes? Is there a way to have the ASP.NET server run a background thread that fires a tick event after a certain elapsed period?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could have a timer in the Application_Start of the Global.asax, but this is not very flexible since you need to do a request to the application for the timer to start. There are dangers to doing it this way though, as detailed by Haacked:

A better way of doing it is to have a web service that acts as an interface to your ASP.NET application and have a windows service that calls your web service on scheduled intervals:

More details here:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...