我有以下代码使用System.Threading.Tasks
private async void UploadDocument(System.IO.FileInfo fileInfo)
{
var someTask = await Task.Run<bool>(() =>
{
// open input stream
using (System.IO.FileStream stream = new System.IO.FileStream(FileTextBox.Text, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
using (StreamWithProgress uploadStreamWithProgress = new StreamWithProgress(stream))
{
uploadStreamWithProgress.ProgressChanged += uploadStreamWithProgress_ProgressChanged;
// start service client
FileTransferWCF.FileTransferServiceClient client = new FileTransferWCF.FileTransferServiceClient();
//FileTransferClient.FileTransferServiceClient client = new FileTransferClient.FileTransferServiceClient();
// upload file
client.UploadFile(fileInfo.Name, fileInfo.Length, uploadStreamWithProgress);
// close service client
client.Close();
}
}
return true;
}).ContinueWith(r =>{
if(r.Result) LogText("Done!!");
});
}
如果我离开这个并尝试编译,我会得到:
“不能将 void 分配给隐式类型的局部变量”** 在
var someTask
所以我然后var someTask
改为Task someTask
但现在我得到了错误:
“无法将类型 'void' 隐式转换为 'System.Threading.Tasks.Task'”。
关于如何处理这个问题的任何线索?