Dhanuka777
Dhanuka777

Reputation: 8616

HostingEnvironment.QueueBackgroundWorkItem support for multiple background processs

I am planning to use HostingEnvironment.QueueBackgroundWorkItem in my project (MVC5) to invoke a background process from a controller as follows.

System.Web.Hosting.HostingEnvironment.QueueBackgroundWorkItem(async cancellationToken =>
                    {
                        var result1 = await AddUsers(userList, param1, param2);
                    });

Will this support multiple background processes to run in parallel? And is there any ways I can optimize my implementation?

Upvotes: 1

Views: 1945

Answers (1)

Stephen Cleary
Stephen Cleary

Reputation: 456767

Yes, it will support multiple background processes, and they do run in parallel.

However, you should carefully consider what those background processes should be doing. QueueBackgroundWorkItem is not reliable in the sense that you can assume the work will complete once it has been queued. An action like "add user" is not an appropriate use case, and you should instead use an architecture with a reliable queue (e.g., Azure queue or MSMQ) and independent backend (e.g., Azure webjob or Win32 service).

Upvotes: 1

Related Questions