【发布时间】:2008-10-23 17:50:11
【问题描述】:
我正在使用 C# 和 .NET 3.5。 OptionA 和 OptionB 有什么区别?
class MyClass
{
private object m_Locker = new object();
private Dicionary<string, object> m_Hash = new Dictionary<string, object>();
public void OptionA()
{
lock(m_Locker){
// Do something with the dictionary
}
}
public void OptionB()
{
lock(m_Hash){
// Do something with the dictionary
}
}
}
我开始涉足线程(主要是为多线程应用程序创建缓存,不使用 HttpCache 类,因为它没有附加到网站),我在很多地方都看到了 OptionA 语法我在网上看到的示例,但我不明白通过 OptionB 完成的原因(如果有的话)。
【问题讨论】:
标签: c# .net multithreading