There doesn't seem to be a method in C# where you can unzip a file using await, so I created a task and I am trying to await that. I get the following error:
Cannot implicitly convert type 'void' to 'System.Threading.Tasks.Task'
When I run this code..
Task taskA = await Task.Run(() => ZipFile.ExtractToDirectory(tempPath + @"\" + ftpFile, pvtdest));
Any thoughts on this would be greatly appreciated! Thank you :)
Just remove the Task taskA =
, like this:
await Task.Run(() => ZipFile.ExtractToDirectory(tempPath + @"\" + ftpFile, pvtdest));
Once you await
a Task
, you usually don't need to do anything else. A Task
doesn't have a result value, so that's why the compiler is complaining about "void". The await
will handle propagating exceptions and continuing the method when your Task.Run
is complete, and that should be all you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With