有不明白的地方欢迎入群 347636249 探讨
System.Threading.Thread.Sleep(500);
ExpertDownloadBind (this, TBView, tableItems, UserID, loadingimglist.ToArray ());
});
Task1.Wait ();
System.Threading.Thread.Sleep(1000);
TBView.Source = new TableSource (this, tableItems, UserID);
TBView.ReloadData ();
/// <summary>
/// 绑定数据并下载文件
/// </summary>
private void ExpertDownloadBind(UIViewController viewcontroller , UITableView tableview,
List<TableItem> listmodel, string userid, params string[] imgarr)
{
string _fullname = string.Empty; //存储文件名
for (int i = 0; i < imgarr.Length; i++) {
_fullname = imgarr [i].Substring (imgarr [i].LastIndexOf ("/") + 1);
string _cp = FileHelper.GetMyDocumentPath (KeyCenter.Key_LoadedImgPath);//获取图片文件夹路径
if (FileHelper.FileUploaded (_cp, _fullname))
continue; //已经下载过了就不下载
string tempimgurl = imgarr [i];
//LoadFile (tempimgurl);
new System.Threading.Thread (() => LoadFile (tempimgurl)).Start ();
}
}
void LoadFile(object fileurl)
{
string name = fileurl.ToString ();
var webClient = new WebClient();
webClient.DownloadDataCompleted += (s, e) => {
var bytes = e.Result; // get the downloaded data
string documentsPath = FileHelper.GetMyDocumentPath (KeyCenter.Key_LoadedImgPath);
string localFilename = name.Substring (name.LastIndexOf ("/") + 1);
string localPath = Path.Combine (documentsPath, localFilename);
File.WriteAllBytes (localPath, bytes); // writes to local storage
};
webClient.DownloadDataAsync(new Uri(name));
}