在IIS上长期运行的进程的担忧 [英] Concerns with long-running process on IIS

查看:120
本文介绍了在IIS上长期运行的进程的担忧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关注:

我经历的职位/描述IIS回收可以随时应用程序池的博客阅读。这是否意味着(在IIS回收应用程序池而言),如果我做一个长期运行的进程同步或异步调用它不会不要紧,因为IIS可以回收应用程序池,并终止长期运行的进程?如果是这样的话,什么是共同的路径,以确保不会发生这种情况?

示例

 公共任务<&的ActionResult GT; LongRunningProcessAsync(SubmitFileModel AMODEL)    {
        返回Task.Run(()=> LongRunningProcess(AMODEL));
    }


解决方案

HostingEnvironment 有一个静态方法,<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.hosting.hostingenvironment.registerobject.aspx\"相对=nofollow> RegisterObject ,可让您将物体放在应用程序的注册对象列表中。

<一个href=\"http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx\"相对=nofollow>据菲尔哈克...


  

在ASP.NET眼泪就下来了的AppDomain中,它会首先尝试调用
  停止方法在所有注册的对象....当ASP.NET调用这个方法,你的code需要prevent这种方法无法返回,直到你的工作就完成了。


另外,你可以创建不是由IIS托管的服务。

Concerns:

I have read through posts/blogs that describe IIS could recycle the app pool at any time. Does this mean (in terms of IIS recycling app pool) it would not matter if I make a call to a long running process synchronous or asynchronous, as IIS could recycle the app pool and terminate the long-running process? If this is the case, what are common paths to make sure this does not happen?

Example

public Task<ActionResult> LongRunningProcessAsync(SubmitFileModel aModel)

    {
        return Task.Run( () => LongRunningProcess( aModel) );
    }

解决方案

HostingEnvironment has a static method, RegisterObject, that allows you to place an object in the list of registered objects for the application.

According to Phil Haack...

When ASP.NET tears down the AppDomain, it will first attempt to call Stop method on all registered objects....When ASP.NET calls into this method, your code needs to prevent this method from returning until your work is done.

Alternatively, you could create a service that is not hosted by IIS.

这篇关于在IIS上长期运行的进程的担忧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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