‘await’运算符只能与异步lambda表达式一起使用

我正在尝试将文件列表复制到目录中。 我正在使用async / await。 但我一直在收到这个编译错误

‘await’运算符只能在异步lambda表达式中使用。 考虑使用’async’修饰符标记此lambda表达式。

这就是我的代码

async Task CopyFilesToFolder(List fileList, IProgress progress, CancellationToken ct) { int totalCount = fileList.Count; int processCount = await Task.Run(() => { int tempCount = 0; foreach (var file in fileList) { string outputFile = Path.Combine(outputPath, file); await CopyFileAsync(file, outputFile); //<-- ERROR: Compilation Error ct.ThrowIfCancellationRequested(); tempCount++; if (progress != null) { progress.Report((tempCount * 100 / totalCount))); } } return tempCount; }); return processCount; } private async Task CopyFileAsync(string sourcePath, string destinationPath) { using (Stream source = File.Open(sourcePath, FileMode.Open)) { using (Stream destination = File.Create(destinationPath)) { await source.CopyToAsync(destination); } } } 

请问有谁可以指出我在这里失踪了什么?

 int processCount = await Task.Run(() => 

应该

 int processCount = await Task.Run(async () => 

请记住, lambda只是定义方法的简写。 所以,你的外部方法是async ,但在这种情况下你试图在lambda中使用await (这是一种你的外部方法不同的方法)。 所以你的lambda也必须标记为async