如果生成的线程仍在工作,则保持 Web 服务处于活动状态
我有一个网络服务,将由夜间作业流程文档调用,每个文档将在其自己的后台处理器上排队并执行。此过程可能需要几个小时或几分钟,具体取决于负载。如果它什么都不做,我不想让它活着。但是,当生成一个线程并立即返回时,即使有一个线程正在工作,空闲时钟也会开始。我尚未将线程设置为 IsBackground,它仍然因空闲而终止。对于我的测试,我将空闲时间设置为 1 分钟。有没有办法让服务保持“活动”状态
这是网络服务代码:
public class LetterInitiateWS : System.Web.Services.WebService
{
private static Processor processor = new Processor();
[WebMethod]
public void ExecuteBulkRun()
{
var thrd = new Thread(() => ThreadExecuteBulkRun());
thrd.IsBackground = false;
thrd.Start();
}
private void ThreadExecuteBulkRun()
{
processor.ExecutBulkRun();
}
}
I have a webservice that will be called by a nightly job process documents, each document will be queued and executed on it's own background processor. This process can take a couple hours or a few munites depending on the load. I don't want to have it alive if it's not doing anything. But when a spawn a thread and return immediately the idle clock begins even though there is a thread working. i have not set the thread to IsBackground and it still terminates for being idle. For my test i set the idle time to be 1 minute. Is there a way to keep the service as being "ALIVE"
Here is the webservice code:
public class LetterInitiateWS : System.Web.Services.WebService
{
private static Processor processor = new Processor();
[WebMethod]
public void ExecuteBulkRun()
{
var thrd = new Thread(() => ThreadExecuteBulkRun());
thrd.IsBackground = false;
thrd.Start();
}
private void ThreadExecuteBulkRun()
{
processor.ExecutBulkRun();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你最好的选择是将其分成两个单独的过程。您将在使用基于 IIS/ASP.NET 的进程并试图使其保持活动状态时遇到麻烦。
如果我是你,我会做类似的事情:
您将在此处的答案中找到类似的建议:
处理执行长时间运行的数据库任务时 Web 服务超时
长时间运行的 Web 服务架构
设计长期运行的资源密集型 Web 服务的建议
I think your best bet is to split this up into two seperate processes. You're going to have trouble with your IIS/ASP.NET based process and trying to keep it alive.
If I were you I'd look to do something like:
You'll find similar suggestions in the answers here:
Handling Web Service Timeouts While Performing Long-Running Database Tasks
Long running webservice architecture
Recommendations for designing a long-running, resource-intensive web service
对于不涉及任何编码的解决方案,您可以通过将默认的空闲超时值 20 分钟更改为 0 来禁用 IIS 的不活动监视器。转到应用程序池中的高级设置,这是应用程序池中的第二个设置“过程模型”部分。
For a solution which doesn't involve any coding, you can just disable IIS' inactivity monitor by changing the default Idle Time-out value of 20 minutes to 0. Go to Advanced Settings in your application pool and this is the second setting in the "Process Model" section.
为了处理这个问题,我创建了一个静态类,当我在 ThreadExecuteBulkRun 中工作时,该静态类有一个计时器,每 5 分钟记录一次 Web 服务页面,该页面会重置 IIS 中的空闲计时器。当该过程完成时,静态类将停止访问网页。
To handle this I created a static class that when I am working in ThreadExecuteBulkRun the static class has a timer that every 5 minutes hist the webservice page which resets the Idle timer in IIS. and when the process completes the static class stops hitting the webpage.