本文介绍了" AsyncFuture< T>"或者是什么?未来< T>在后台线程获得的 - 它是一个模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有在后台线程,创建为它未来的变种,再后来要求的计算值一样简单做了一些工作。

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#-code:

AsyncFuture<int> asyncFuture = new AsyncFuture<int>(FuncToCalculateValue);

//do some other work, or draw UI

if(asyncFuture.NoErrorsHappened){
   int realResult = asyncResult.Value;
}



我可以通过我自己的实现这样的类型,但我的问题是:不是个吨,有些种类的已知图案的?是否有可能一个名字,或者甚至是一个框架的实施?大概在.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,我真的很喜欢的的。有一些 rel=\"nofollow\">对利弊的意见。

Yacoder, I really like Ayende's two Future implementations. There is some good discussion from Jon Skeet in the comments on the cons.

这篇关于&QUOT; AsyncFuture&LT; T&GT;&QUOT;或者是什么?未来&LT; T&GT;在后台线程获得的 - 它是一个模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!