What exactly is the difference using
Task.Run(() => {
LongRunningMethod();
});
or
HostingEnvironment.QueueBackgroundWorkItem(clt => LongRunningMethod());
I tested on an Asp.Net MVC application in which I kept on writing a line to a text file for about 10 minutes inside an asynchronous task which is invoked using Task.Run or QBWI.
It goes fine both using Task and QBWI. My async method keeps on writing to that file without any issues till 10 minutes. No disturbance from IIS I observed regarding its recycling.
So what is special about QueueBackgroundWorkItem then?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…