什么运行时间上的共享主机定期在ASP.NET脚本消耗的最佳方式? [英] Whats the best way to run a time consuming script in ASP.NET at regular intervals on shared hosting?

查看:86
本文介绍了什么运行时间上的共享主机定期在ASP.NET脚本消耗的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定期运行一个耗时的脚本(更新从第三方API数据库)。我不知道这样做的最好的做法是什么:

I would like to run a time consuming script (to update a database from a 3rd party API) at regular intervals. I was wondering what the best practice for this would be:


  1. 应该采取什么'脚本'是 - 一个ASP.NET服务?记住我的共享主机轴承,这是不可能的(但我想知道)。

  2. 如何可以在脚本安排定期/在设定的时间自动运行?

在此先感谢!

推荐答案

你可以做的是在Global.asax中添加一个System.Timers.Timer。

What you can do is add a System.Timers.Timer in Global.asax.

System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(TimerElapsed), null, new Timespan(0), new Timespan(24, 0, 0));

// This will run every 24 hours.
private void TimerElapsed(object o)
{
    // Do stuff.
}

在IISManager,启用HTTP-保持有效指示,为您的应用程序。

In IISManager, enable HTTP-Keep Alives for your application.

在IIS管理器中,选择HTTP响应头模块,打开它,并在操作窗格中,选择设置,通用报头,并在那里选择启用保持HTTP连接指令。

In IIS Manager, select Http Response Headers Module, open it and in the Actions Pane, select Set Common Headers and in there select Enable Http Keep Alives.

此外,检查您的应用程序池的设置 -

Also, check for a setting of your application pool -

选择您的应用程序的应用程序池,从右边的操作选择高级设置选项卡。

Select the application pool of your application, select Advanced Settings from the right Actions Tab.

在那里有一个叫设置 - 空闲超时(分)

In there there is a setting called - Idle Timeout (minutes)

默认情况下为20分钟。让它像60分钟或增加甚至更多,检查。

By default it is 20 Minutes. Make it something like 60 Minutes or increase it even more and check.

这篇关于什么运行时间上的共享主机定期在ASP.NET脚本消耗的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆