Lazy.Force()和Lazy.Value有什么区别 [英] What's the difference between Lazy.Force() and Lazy.Value

查看:107
本文介绍了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.

这篇关于Lazy.Force()和Lazy.Value有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆