【发布时间】:2015-10-25 14:22:46
【问题描述】:
我有以下模式:
task<Param1^> MyClass::MethodA(String^ s)
{
return create_task([this, s]
{
....
IAsyncOperation<Param1^>^ result = SystemMethod1ReturningParam1(...);
return result;
});
}
IAsyncOperation<Param2^>^ MyClass::MethodB(String^ s)
{
return create_async([this, s]
{
return MethodA(s).then([this](task<Param1^> t)
{
Param1^ p1 = t.get();
....
Param2^ result = SystemMethod2ReturningParam2(p1);
return result ;
});
});
}
我调用 public MethodB 调用私有 MethodA。 Param1 是我无法更改的标准枚举。 MethodA create_task 我需要返回错误条件。我不能返回空值。 MethodB 也需要返回错误条件。
从这两种方法返回错误的最佳方法是什么?
SystemMethod1ReturningParam1 和 SystemMethod2ReturningParam2 是框架系统方法,可以抛出异常。我在哪里抓到他们?
【问题讨论】:
-
我不想这么说,但是通过 WinRT 学习 C++ 或并发性是一种不好的做法。尝试先使用标准来理解它..
-
我非常精通经典C++和经典并发。
-
只需rtfm first,然后提出一个重点问题,表明您正在尝试使用现有的东西。
-
该代码肯定不是 C++。它看起来像一个叫做 C++/CLI 的东西,完全不同。
标签: concurrency win-universal-app c++-cx