【发布时间】:2013-02-13 11:31:20
【问题描述】:
我有一种方法可以将一个文件上传到服务器。除了方法上的任何错误编码之外,现在正在工作(我是任务库的新手)。
这是将文件上传到服务器的代码:
private async void UploadDocument()
{
var someTask = await Task.Run<bool>(() =>
{
// open input stream
using (System.IO.FileStream stream = new System.IO.FileStream(_cloudDocuments[0].FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
using (StreamWithProgress uploadStreamWithProgress = new StreamWithProgress(stream))
{
uploadStreamWithProgress.ProgressChanged += uploadStreamWithProgress_ProgressChanged;
// start service client
SiiaSoft.Data.FieTransferWCF ws = new Data.FieTransferWCF();
// upload file
ws.UploadFile(_cloudDocuments[0].FileName, (long)_cloudDocuments[0].Size, uploadStreamWithProgress);
// close service client
ws.Close();
}
}
return true;
});
}
然后我有一个 ListBox,我可以在其中拖放多个文件,所以我想做的是在 ListBox 文件中执行 FOR LOOP,然后调用 UploadDocument(); 但我想先在 listBox 中上传第一个文件完成后继续第二个文件,依此类推...
有什么最好的方法吗?
非常感谢。
【问题讨论】:
标签: c# task-parallel-library async-await