APM异步编程模型

yangyi_2009 yangyi_2009 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

class C
{
void X()
{
A a = new A();
State state = new State() { A = a };
IAsyncResult result = a.BeginAAA(AReceived, state);
}
void AReceived(IAsyncResult ar)
{
State state = (State)ar.AsyncState;
A a = state.A;
ResultA resA = a.EndAAA(ar);
B b = b.BeginBBB();
state.B = b;
IAsyncResult result = stream.BeginRead(BReceived, state);
}
void BReceived(IAsyncResult ar)
{
State state = (State)ar.AsyncState;
B b = state.B;
ResultB resB = b.EndRead(ar);

DoSomething(resB); // 最终结果
}
}


如果不用通过引发事件来返回结果的方法,
而是通过:
为类 C 实现一对 BeginCCC 和 EndCCC 方法;
或者为类 C 实现返回 Task<T> 的 CCCAsync 方法。
返回最终结果。应该如何实现?

...全文
评论 4
收藏 已收藏
分享
返回顶部
yangyi_2009
C# 111,129 成员 642,539 内容