问题描述
我想在后台线程中完成一些工作,就像创建一个Future var一样简单,然后再询问计算的值。
I'd like to have some work done in a background thread as simple as creating a Future var for it and then asking later for the calculated value.
伪C#代码:
AsyncFuture<int> asyncFuture = new AsyncFuture<int>(FuncToCalculateValue);
//do some other work, or draw UI
if(asyncFuture.NoErrorsHappened){
int realResult = asyncResult.Value;
}
我可以通过我自己来实现这种类型,但我的问题是:isn'那种某种已知的模式?有可能是一个名字,甚至是一个框架实现?可能在.NET 4.0中?
I can implement such type by my own, but my question is: isn't that some kind of a known pattern? Is there maybe a name for it, or maybe even a framework implementation? Probably in .NET 4.0?
如果它是一种模式,与之相关的陷阱是什么?
And if it is a pattern, what are the pitfalls associated with it?
推荐答案
Yacoder,我真的很喜欢。有一些在对cons的评论中。
Yacoder, I really like Ayende's two Future implementations. There is some good discussion from Jon Skeet in the comments on the cons.
这篇关于" AsyncFuture< T>"或者是什么?未来< T>在背景线程中获得 - 是一种模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!