Running a job in the background

I need a block of code that runs a job in the background. Suppose the user clicks the Submit button, then the task starts in the background, while the user closes this window and starts another task, and the task should continue.

Please provide some help with ASP.NET and VB.NET.

Many thanks for your help

+3
source share
5 answers

You can take a look at the ThreadPool.QueueUserWorkItem method , which allows you to run some method on a thread drawn from a thread pool. Alternatively, you can use the Thread class to create a new thread manually, if it is a long-running task, to avoid the danger of a thread from a pool that contains a limited number of threads and which are also used to serve requests in ASP.NET applications.

+5
source

You can do this by creating a Windows service hosting the wcf service, when the user clicks the submit button, you can send a request to the Windows service, and the Windows service will start in the background event when the user closes the window.

+4

A BackgroundWorker . DoWork.

+1

You can use BackgroundWorker , depending on your context.

0
source

BackgroundWorker will run in the background and can be easily used to synchronize updates with your GUI, if necessary.

Or use a parallel task library ...

0
source

Source: https://habr.com/ru/post/1780445/


All Articles