如何访问链中先前任务返回的变量?

时间:2012-12-09 20:52:30

标签: windows-8 c++-cx

我有以下任务链,我想在上一个任务中访问变量decoder,但是在更早的任务中创建。

create_task(file->OpenReadAsync()).then([](IRandomAccessStream^ inStream) {
    return BitmapDecoder::CreateAsync(inStream);

}).then([localFolder](BitmapDecoder^ decoder) {
    return localFolder->CreateFileAsync("map.png", CreationCollisionOption::ReplaceExisting);

}).then([](StorageFile^ outFile) {
    return outFile->OpenAsync(FileAccessMode::ReadWrite);

}).then([](IRandomAccessStream^ outFileStream) {
    return BitmapEncoder::CreateAsync(BitmapEncoder::PngEncoderId, outFileStream);

}).then([](BitmapEncoder^ encoder) {
    BitmapPixelFormat pixelFormat = decoder->BitmapPixelFormat; // how do I make decoder available here?
    // Do stuff that uses encoder & decoder
});

1 个答案:

答案 0 :(得分:0)

最后,我只是将我需要的变量分配给包含任务链的函数的局部变量。