Thread.Start() versus ThreadPool.QueueUserWorkItem()

前端 未结 7 2113
长发绾君心
长发绾君心 2020-12-12 16:20

The Microsoft .NET Base Class Library provides several ways to create a thread and start it. Basically the invocation is very similar to every other one providing the same k

7条回答
  •  情歌与酒
    2020-12-12 17:05

    In .NET 4.5.2 they added a new method: HostingEnvironment.QueueBackgroundWorkItem.

    This appears to be an alternative to ThreadPool.QueueUserWorkItem. Both behave similarly, but there are some nice benefits to using the new method when working in ASP.NET:

    The HostingEnvironment.QueueBackgroundWorkItem method lets you schedule small background work items. ASP.NET tracks these items and prevents IIS from abruptly terminating the worker process until all background work items have completed. This method can't be called outside an ASP.NET managed app domain.

提交回复
热议问题