我有一个 c++ 类对象,它在 uwp 应用程序的后台执行一些处理。
它的进程操作由 Unity 的“更新”方法调用 ~60fps 通过 UWP IAsyncOperation
。
该类有一个isBusy
属性,该属性true
在调用操作后设置为,以便在它完成之前阻止它再次从统一调用。
使用任务继续,我想在处理完成后将其设置为 false 并通过IAsyncOperation
.
IAsyncOperation<ResultsWrapper^>^ SomeClass::SomeClassUpdateMethod() {
return concurrency::create_async([this]() -> ResultsWrapper^
{
// Block processing
SomeClass::isBusy = true;
// Process image and return to await
LongRunningTask().then([this]() {
return SomeClass::TaskResults;
}).then([this]() {
isBusy = false;
});
});
}
concurrency::task<void> SomeClass::LongRunningTask(){
auto results = ref new TaskResults();
'''Work happens here'''
SomeClass::TaskResults = results;
}
我期望发生的事情是将ResultWrapper
对象返回到调用应用程序(Unity)的主线程,然后isBusy
任务继续将对象的标志设置为 false。
会发生什么:
Error C2338 incorrect parameter type for the callable object in 'then'; consider _ExpectedParameterType or task<_ExpectedParameterType> (see below) \....\include\ppltasks.h