ASP.NET MVC Repeating Task

后端 未结 2 930
一个人的身影
一个人的身影 2021-01-03 04:17

I need to run a task repeatedly on an ASP.NET MVC site; it needs to run every time interval (Interval doesn\'t matter).

I achieved this by setting a backgro

2条回答
  •  伪装坚强ぢ
    2021-01-03 05:04

    Stackoverflow itself uses (or at least used to use) a cunning way of doing this. See here: http://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/

    In brief, you do this:

    1. At startup, add an item to the HttpRuntime.Cache with a fixed expiration.

    2. When cache item expires, do your work, such as WebRequest or what have you.

    3. Re-add the item to the cache with a fixed expiration.

提交回复
热议问题