Asynchronous task in ASP.NET

后端 未结 4 574
野的像风
野的像风 2021-01-16 06:51

I’m trying to force an ASP.NET site to pre-load a large number of objects into the cache on start-up. Each objects takes 2-10 seconds to generate, which means loading 1200+

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-16 07:33

    Use the Task Parallel Library (if you are using .Net 4.0). Each implementation of the TPL is designed for the specific host, and there's one for ASP.NET, which means you have your own TaskScheduler and SynchronizationContext that complies with the rules that IIS imposes when it comes to threading and threading context.

    There's a very good MSDN article explaining the diferent TPL behaviours here.

    Using the TPL is very simple if you are familiar with Lambda Expressions, and saves you a lot of underground code managing threads and thread pools.

提交回复
热议问题