我在 ASP.NET 4.0 Web 应用程序的 Global.asax 中有以下代码
protected void Application_Start(object sender, EventArgs e)
{
Dictionary<string, string> AllCompanyList = new Dictionary<string, string>();
Application.Add("GlobalCompanyList", AllCompanyList);
Thread ProcessCompanyThread = new Thread(new ParameterizedThreadStart(CompanyThread.Start));
ProcessCompanyThread.IsBackground = true;
ProcessCompanyThread.Start(AllCompanyList);
}
我在另一个页面上通过
Dictionary<string, string> AllCompanyList = (Dictionary<string, string>)HttpContext.Current.Application["GlobalCompanyList"];
首先,“GlobalCompanyList”在 IIS 的生命周期中是否只有一个实例?
其次,在 ProcessCompanyThread 中访问或修改“GlobalCompanyList”线程是否安全?如果不是,那么我必须做什么才能使其线程安全?
感谢帮助。