Click here to Skip to main content
15,888,070 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
VB
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:
VB
Dim x As New LongMethods.LongProcessAsync(AddressOf LongMethods.LongProcess)
x.BeginInvoke(AddressOf LongMethods.LongProcessCallback, Nothing)
Posted
Comments
db7uk 2-Oct-13 15:54pm    
If this is a web application, how many concurrent users would execute the long running processes?
woopsydoozy 2-Oct-13 16:10pm    
Ideally never more than 1. It's meant to be invoked through a nightly automated process, but for now we're doing it manually on a hidden admin page.

1 solution

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.
 
Share this answer
 
v2
Comments
Zoltán Zörgő 2-Oct-13 16:55pm    
Agree (+4). But not because it is threaded. The processing pipeline is more complex than that. First of all there is a running timeout for every working thread. It would be a waste of resources and a big hole if this would be set this to minutes. Spawning a process is good if there is no feedback needed, and there is no real chance for something to go wrong (because the application is loosing control over the process created - the later will probably work even after the IIS working thread is recycled) - for the other cases the service and some IPC is a better approach.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900