如何在ASP.NET中启动一个漫长的过程 [英] How to kick off a long process in ASP.NET

查看:60
本文介绍了如何在ASP.NET中启动一个漫长的过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从ASP.NET Web应用程序启动长进程的最佳方法是什么?我不需要任何返回数据,我甚至不需要告诉用户何时完成,我只需要启动并运行直到完成。我以为我是通过异步调用进程来正确地做到这一点,但它仍然在4分钟左右超时,就像没有异步调用一样。我不想做毯子web.config调整,如果我可以帮助它。我是否需要在Web服务后面的方法以某种方式分离线程?或者更糟糕的是,将它放在Windows服务或调用的单独应用程序中?



这里基本上就是我现在所做的。在漫长的流程类中:

What's the best way to kick off a long process from an ASP.NET web application? I don't need any return data, I don't even need to tell the user when it's done, I just need the process to kick off and run until it's complete. I thought I was doing it correctly by just invoking the process asynchronously, but it's still timing out at around 4 minutes, same as without the asynch call. I don't want to do the blanket web.config adjustment if I can help it. Do I need my method behind a web service to somehow separate the threads? Or worse, have it in a Windows service or separate application that gets invoked?

Here is basically what I'm doing at this point. In the long process class:

Public Shared Sub LongProcess()
    Using dt As DataTable = GetMyData()
        For Each dr As DataRow In dt.Rows
            DoSomeProcess()
        Next
    End Using
End Sub
'asynch methods for LongProcess
Public Delegate Sub LongProcessAsync()
Public Shared Sub LongProcessCallback(ar As IAsyncResult)  'just close out the thread
    DirectCast(DirectCast(ar, System.Runtime.Remoting.Messaging.AsyncResult).AsyncDelegate, LongProcessAsync).EndInvoke(ar)
End Sub





然后在按钮上点击我的页面:



Then in the button click on my page:

Dim x As New LongMethods.LongProcessAsync(AddressOf LongMethods.LongProcess)
x.BeginInvoke(AddressOf LongMethods.LongProcessCallback, Nothing)

推荐答案

单独的预定Windows服务/控制台应用程序是实现此目的的最佳方式。我们不应该在ASP.NET应用程序中调用long进程,因为它是基于线程的应用程序。
Separate scheduled windows service / console application is the best way to achieve this. We should not call the long process in ASP.NET application since it is thread based application.


这篇关于如何在ASP.NET中启动一个漫长的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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