0

I have a C# ASP.NET web application which starts a thread running some methods in a class called SiteCrawler.cs.

In HttpContext.Current.Application I want to save some value when all the threads are finished running. My problem is that the HttpContext.Current object is null in the spawned threads because it doesn't exist there.

I have tried to search around every inch of Stackoverflow to find a solution but without any luck....

4

1 回答 1

0

我建议在生成线程时将 HttpContext 作为参数传递。就个人而言,我会删除您对 HttpContext 的依赖并创建一个对象,其工作是同步您的线程(或存储它们的结果),并可用于在并行处理完成后执行后期处理。

HttpContext.Current.Application 是一个单例,它将存在于所有线程中......这是一个网络应用程序吗?如果不是,您始终可以自己初始化应用程序并将其分配给 HttpContext.Current.Application。

于 2012-07-25T04:53:53.773 回答