Lazy.Force()和Lazy.Value有什么区别
问题描述:
关于MSDN文档上的Lazy.Force<T>
扩展方法说:
On the MSDN documentation for Lazy.Force<T>
extension method says:
强制执行此值并返回其结果.与...一样 价值.互斥用于防止其他线程也 计算值.
Forces the execution of this value and returns its result. Same as Value. Mutual exclusion is used to prevent other threads from also computing the value.
这是否意味着等同于使用ExecutionAndPublication
创建Lazy<T>
实例 LazyThreadSafetyMode ,这样只有一个线程可以初始化实例?
Does it mean that it's equivalent to creating a Lazy<T>
instance with ExecutionAndPublication
LazyThreadSafetyMode so that only one thread can initialize the instance?
谢谢
答
是.它们都相同,并且都确保只计算一次该值.
Yes. They are both the same, and both make sure that the value will be computed only once.