VJAI VJAI - 1 year ago 61
C# Question

Running long-time background task in a separate background thread vs process

I'm building a ASP.NET Core web application and I need to run some complex tasks that takes quite some time to finish up, from seconds to minutes. The user don't have to wait till the complete task runs but someway I need to update the UI with the progress of the task. I'm thinking of two ways to handle this in the ASP.NET server: one is using a background thread and another is using a separate process. I don't want the long running task hamper the web application in any way. Is using a thread is a safe option compared to a process? or running these tasks in a separate process is a better and efficient way?

Answer Source

I'd say do it in another process. Put it in a queue and have a separate process handle that queue and when finished signal the web app by posting a job complete message or something.

If you use a regular thread inside the web app and the server is shutdown in the middle of the process, or the web app is recycled you might get some undesired effects.

Some other options are outlined here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download