ASP.NET Site - Firing some code at a specific time

怎甘沉沦 提交于 2019-12-12 11:27:47

问题


I'm planning on building an ASP.NET web site, which will be on a shared hoster. I don't have an option for a windows service for this. What are my options specific to a web site where I can execute a task, say at 3 AM in the morning? Maybe kicking off a separate thread, or something?

Thanks.


回答1:


Seem legit




回答2:


I was just about to do something similar.

What needs to happen is a seperate thread needs to be kicked off from the Global.asax.

void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup

    }

You will also need to account that the application pool will recycle many times, so make sure it is based on a specific time and that you also have a Database that stores whether it has run or not incase the app pool recycles over the 3am mark, which is highly likely.

You will also need to have some form of keep alive service as if your website goes inactive the app pool won't restart until someone hits it.




回答3:


We handle this sort of activity in one of two ways:

1) Kick off a thread in global.asax Application_Start that is responsible for executing the activities at the appropriate time.

2) Store a dummy object in the HttpRuntime.Cache with a specified timeout on application startup and have it perform the activities in the CacheItemRemovedCallback.



来源:https://stackoverflow.com/questions/8584909/asp-net-site-firing-some-code-at-a-specific-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!