c# - Difference between Task.Run and QueueBackgroundWorkItem in Asp.Net -


what difference using

task.run(() => {       longrunningmethod(); }); 

or

hostingenvironment.queuebackgroundworkitem(clt => longrunningmethod()); 

i tested on asp.net mvc application in kept on writing line text file 10 minutes inside asynchronous task invoked using task.run or qbwi.

it goes fine both using task , qbwi. async method keeps on writing file without issues till 10 minutes. no disturbance iis observed regarding recycling.

so special queuebackgroundworkitem then?

the documentation has excellent explanation:

differs normal threadpool work item in asp.net can keep track of how many work items registered through api running, , asp.net runtime try delay appdomain shutdown until these work items have finished executing. api cannot called outside of asp.net-managed appdomain. provided cancellationtoken signaled when application shutting down.

task.factory.startnew not register work asp.net runtime @ all. you're running code 10 minutes, makes no difference. iis recycle happens @ particular times preset in iis. if want test whats going on, can attempt force recycle.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -