简体   繁体   English

在后台ASP.NET中继续运行代码

[英]Continue running code in background ASP.NET

I need to run the code every 15 seconds in background which is not effect on server. 我需要每15秒在后台运行一次代码,这对服务器没有影响。

I have below a sample table for auction data. 我在下面的样本表中有拍卖数据。

--------------------------------------------------------------
AID           STARTDATE               ENDDATE
-------------------------------------------------------------
1             18-7-2013 12:00 PM     20-7-2013 12:00 PM
2             19-7-2013 12:00 PM     21-7-2013 12:00 PM
3             19-7-2013 01:00 PM     21-7-2013 12:00 PM
4             19-7-2013 01:00 PM     22-7-2013 12:00 PM

i need to check in table for get the item which is present date is greater than start date, then i will get the data through the web request that auction store in local db, it will be loop for every 15 secs until the present date is greater than enddate. 我需要签入表以获取当前日期大于开始日期的项目,然后我将通过Web请求获取拍卖数据存储在本地数据库中的数据,它将每15秒循环一次,直到当前日期为大于结束日期。 Some time 2 auction start at same time then i need to run two thread simultaneously. 某个时间2拍卖同时开始,那么我需要同时运行两个线程。

What is the best way to get an update every 15 seconds for all items which are currently in running auction mode and store in our database? 对于当前处于拍卖模式并存储在我们数据库中的所有商品,每15秒更新一次的最佳方法是什么?

Thank you in advance... 先感谢您...

You can't do that reliably in ASP.NET/IIS. 您不能在ASP.NET/IIS中可靠地做到这一点。 The whole process by default doesn't start until the first request from the web server is received, then the whole process shuts down after the specified inactivity time (usually 20 minutes). 默认情况下,整个过程直到收到Web服务器的第一个请求才开始,然后在指定的不活动时间(通常为20分钟)后关闭。 If you need a process to run every 15 seconds, you have to initial a request from the client side every 15 seconds, most likely using some sort of javascript to do the request. 如果您需要一个进程每15秒运行一次,则必须每15秒从客户端发出一个请求,最有可能使用某种JavaScript来执行请求。

Best solution is to update your your auction database with a windows service, separate from the website. 最好的解决方案是使用与网站分开的Windows服务来更新您的拍卖数据库。

Where are you hosting your website? 您在哪里托管您的网站? If you are on your own server, create a cron job that makes a request to your backend every 15 seconds. 如果您在自己的服务器上,请创建一个cron作业,该作业每15秒向您的后端发出一次请求。

If you are using cloud providers (or providers without the "cloud" catchphrase), they might offer cron job functionality. 如果您使用的是云提供程序(或没有“云”流行语的提供程序),则它们可能提供cron作业功能。 But they rarely let you implement 15-second intervals, which, if it comes from a different site, some providers might interpret as DOS attacks. 但是它们很少让您实现15秒的间隔,如果间隔来自另一个站点,则某些提供程序可能会将其解释为DOS攻击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM