I have a lambda expression with an async call inside
public async Task UploadFile(string id)
{
Progress<double> progress = new Progress<double>(async x =>
{
await Clients.Client(id).SendAsync("FTPUploadProgress", x);
});
await client.DownloadFileAsync(localPath, remotePath, true, FluentFTP.FtpVerify.Retry, progress);
}
I want to call the async method when progress is changed.
I'm getting the following warning:
This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API call
How can I make this method asynchronous?
Should I rewrite the lambda with a System.Action<T> class?
UploadFileis marked asasyncyet there's not a singleawaitin itSendAsynccall inside the progress delegate? You should move that into the outer method. Then if you want to use the progress, you should pass it into a method that accepts aProgressparameter and implement the progress logic in the lambda expression.awaitoperator as the warning states. Anasyncmethod needs to have anawaitoperator, otherwise, it's not asynchronous. The one you had inside the progress delegate does not belong to it.