??????????????Щ???????????????????????????????IIS?????ù???????????????????????????????????????????Щ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????.NET Framework5.0????????????????μ???????????????????????????????????????????????????н??????????汾??Framework?л???????????????????Щ????????????API????????????????????????????
??????????
????????????????????????????????????????????????????“???????”?????????????????к???????????????繃??????????????????????????????????????????????????????????????????????????????????????????????????????С?????????????????????????????????????.NET?????????????????Щ????????????????ж??????????????????????????????IO???????????????????????????????????????????????????????????????????????????????????????Щ?????????????????????????????????????????????????????????????
????????????.NET?У????????????????????????飬??????????????????????????????г????????????????y?????????????????????????????????????????????á?
???????????????
????????????????????????????????????????????????????????????е?????????????????????????????????????????????????????????????????ó???????????????????????????????????????????????????ID???????????CPU??????????????????治????????????????????????????????????????????????顣
????????????????????????????????????????????????????????????????????????????????????У???????????????????????????ó?????????????????????????
??????????????????????????????????????????????????????ι?????????????????while????????????if??????try????????using?飿????????“??????????”??
???????????????????
????public int SumPageSizes(IList<Uri>uris)
????{
????int total=0;
????foreach(var uri in uris)
????{
????txtStatus.Text=string.Format("Found{0}bytes..."??total);
????var data=new WebClient().DownloadData(uri);
????total+=data.Length;
????}
????txtStatus.Text=string.Format("Found{0}bytes total"??total);
????return total;
????}
????????????????uri?б?????????????????????С????????????????????????????????????UI??????????????????????????????????????????????UI???????????????UI???????????£?????????
???????????????????????????????????UI??????????????UI??????????????????????????????????????????仨????o?????????????е????????????????????????????????У?WebClient??????????汾??DownloadData????—DownloadDataAsync????????????????????DownloadDataCompleted?????????????????????д??????汾????????????????£????????????????????????UI?????????????????????UI?????????????γ????
????public void SumpageSizesAsync(IList<Uri>uris)
????{
????SumPageSizesAsyncHelper(uris.GetEnumerator()??0);
????}
????public void SumPageSizesAsyncHelper(IEnumerator<Uri>enumerator??int total)
????{
????if(enumerator.MoveNext())
????{
????txtStatus.Text=string.Format("Found{0}bytes..."??total);
????var client=new WebClient();
????client.DownloadDataCompleted+=(sender??e)=>{
????SumPageSizesAsyncHelper(enumerator??total+e.Result.Length);
????};
????client.DownloadDataAsync(enumerator.Current);
????}
????else
????{
????txtStatus.Text=string.Format("Found{0}bytes total"??total);
????}
????}
????????????????????????????????????foreach??????????????????enumerator????????????????????????????????????????????????????????????????????ɡ????????????????
??????????????????????????????????μ?????汾?????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????й?????????????????????????????汾?У?????????????????????????????????????????????ò????????????????
?????????Щ????????????????????
????public void SumpageSizesAsync(IList<Uri>uris??Action<int??Exception>callback)
????{
????SumPageSizesAsyncHelper(uris.GetEnumerator()??0??callback);
????}
????public void SumPageSizesAsyncHelper(IEnumerator<Uri>enumerator??int total??Action<int??Exception>callback)
????{
????try
????{
????if(enumerator.MoveNext())
????{
????txtStatus.Text=string.Format("Found{0}bytes..."??total);
????var client=new WebClient();
????client.DownloadDataCompleted+=(sender??e)=>
????{
????SumPageSizesAsyncHelper(enumerator??total+e.Result.Length??callback);
????};
????client.DownloadDataAsync(enumerator.Current);
????}
????else
????{
????txtStatus.Text=string.Format("Found{0}bytes total"??total);
????enumerator.Dispose();
????callback(total??null);
????}
????}
????catch(Exception ex)
????{
????enumerator.Dispose();
????callback(0??ex);
????}
????}
?????????????Щ??????????????????????????????JB??????
???????2?????????????????????????????????????????????滻??????????????????????foreach????У?????????????????????????????и???????????????????SubPageSizesAsync???????????
????????????????????????????????????Щ?????????????????????????????????????????к????????????????????????????????????????BUG??
????????μ???
????????????????????μ??????????????????????汾??????????????????
????public async Task<int>SumPageSizesAsync(IList<Uri>uris)
????{
????int total=0;
????foreach(var uri in uris)
????{
????txtStatus.Text=string.Format("Found{0}bytes..."??total);
????var data=await new WebClient().DownloadDataTaskAsync(uri);
????total+=data.Length;
????}
????txtStatus.Text=string.Format("Found{0}bytes total"??total);
????return total;
????}
??????????????????????????е??????????汾????????????????????????δ??????????п????κε????????????????????????л???????????????????Щ?????????????????????
?????????????????Task<int>?????????????Int?????Task??Task<T>????????framework???????????????????????е??????
?????????????ж???????????????????????????汾???????????????????????Async????μ?????????????е?????????????????????????????????????????????е???????????????????????????Task<int>????????????
????????????????????????????????????????????????DownloadDataTaskAsync???????????????Task<byte[]>?????????????????????????????????????????????????????????????????????κ??£????????????await?????????????ɡ?
??????????await?????????????????task????????????????????????????????????????????????????????????????????????????л????