Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use HostingEnvironment.QueueBackgroundWorkItem in a WCF application

Tags:

.net

asp.net

wcf

My understanding is that the HostingEnvironment.QueueBackgroundWorkItem API was introduced so one could spawn a new thread in an Asp.net application, and this new thread wouldn't immediately terminate when the AppDomain is signaled to shutdown (for example, if someone does an IIS app pool recycle). Instead, it will wait some time to try to complete it's work normally before shutting down the AppDomain. Can I use this same API in a WCF application? If not, is there equivalent functionality in the WCF stack? Or can this not be done reliably in WCF, and requires some kind of persistent queue?

like image 751
Rob Quick Avatar asked Apr 23 '26 10:04

Rob Quick


1 Answers

According to the MSDN documentation, it will only work with ASP.NET. The reference source shows that an InvalidOperationException is thrown when calling QueueBackgroundWorkItem() without an ASP.NET environment. I can confirm that the exception occurs when attempting to use this feature in WCF.

like image 144
piedar Avatar answered Apr 25 '26 00:04

piedar