create_task の実装外で Uri^ を定義しようとしています。Java では、非同期タスクに final 修飾子を追加すると、非同期コード内でその変数 (final 修飾子付き) を使用できるようになります。
非同期コード内で以下のコードから Uri^ ソースを使用するにはどうすればよいですか?
void addDownload(Uri^ source, StorageFolder^ destinationFolder, String^ fileName) {
boolean requestUnconstrainedDownload = false;
IAsyncOperation<StorageFile^>^ asyncOperationStorageFile = destinationFolder->CreateFileAsync(fileName, CreationCollisionOption::GenerateUniqueName);
auto createStorageFileTask = create_task(asyncOperationStorageFile);
createStorageFileTask.then([] (StorageFile^ destinationFile) {
BackgroundDownloader^ downloader = ref new BackgroundDownloader();
DownloadOperation^ downloadOperation = downloader->CreateDownload(source, destinationFile);
downloadOperation->Priority = BackgroundTransferPriority::Default;
HandleDownloadAsync(downloadOperation, true);
});
}