Asynchronous 在Lambda[C+;+;/CX]中调用其他函数

Asynchronous 在Lambda[C+;+;/CX]中调用其他函数,asynchronous,windows-8,windows-store-apps,c++-cx,Asynchronous,Windows 8,Windows Store Apps,C++ Cx,我正在开发一个Windows应用商店应用程序(C++)。该应用程序使用Web服务从数据库加载数据,我希望该数据显示在页面上。 为什么我不能调用函数w.r.t作为在封闭函数中创建的类的实例?这是我的应用程序第一页的LoadState事件 void ItemsPage::LoadState(Object^ navigationParameter, IMap<String^, Object^>^ pageState) { (void) pageState; StorySou

我正在开发一个Windows应用商店应用程序(C++)。该应用程序使用Web服务从数据库加载数据,我希望该数据显示在页面上。 为什么我不能调用函数w.r.t作为在封闭函数中创建的类的实例?这是我的应用程序第一页的LoadState事件

void ItemsPage::LoadState(Object^ navigationParameter, IMap<String^, Object^>^ pageState)
{
    (void) pageState;
    StorySource^ storysource = ref new StorySource();

    task<wstring> (GetFromDB(cancellationTokenSource.get_token()))
.then([this, storysource](task<wstring> response){
            try
            {
                auto resp = response.get();
                storysource->Init(resp);
                DefaultViewModel->Insert("Items", storysource->AllGroups);
             }
             catch(COMException^ ex)
             {  ...  }
        });
}
void ItemsPage::LoadState(对象^navigationParameter,IMap^pageState)
{
(无效)页面状态;
StorySource^StorySource=ref new StorySource();
任务(GetFromDB(cancellationTokenSource.get_token()))
。然后([此,故事源](任务响应){
尝试
{
auto resp=response.get();
故事源->初始化(resp);
默认视图模型->插入(“项目”,故事源->所有组);
}
捕获(COMException ^ex)
{  ...  }
});
}
我无法在.then()块内执行任何函数。我需要以某种方式将GetFromDB()的完成链接到StorySource::Init(),并将其链接到DefaultViewModel->Insert()


我对异步编程非常陌生。请解释我做错了什么,我的问题有什么解决办法。提前感谢。

一条建议:将异步任务的结果传递到lambda而不是任务,并在继续中使用单独的错误处理程序闭包,而不是
尝试{auto resp=task.get()}catch…
,除此之外,错误代码或其他错误描述将对您有所帮助。感谢您的帮助。。。在then()块的末尾添加“task\u continuation\u context::use\u current()”后,它现在开始工作。