我不想使用downloadfileAsync事件我使用的下載文件任何完成的事件是有的,只有下載文件,任何想法或任何其他方式告訴我,謝謝提前。webclient下載文件,但沒有執行完成
if (!item.IsInstalled && item.IsChecked)
{
string filename = Path.Combine(Path.GetTempPath(), "AlisAppTemp", "Silverlight");
using (StreamWriter sw = new StreamWriter(filename))
{
sw.WriteLine("Error");
}
client.DownloadProgressChanged += client_DownloadProgressChanged;
client.DownloadFileCompleted += client_DownloadFileCompleted;
client.DownloadFile(new Uri("http://download.microsoft.com/download/F/8/C/F8C0EACB-92D0-4722-9B18-965DD2A681E9/30514.00/Silverlight_x64.exe"), filename);
item.IsDownloaded = true;
}
private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double byteIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = byteIn/totalBytes * 100;
DownloadData = "Download " + e.BytesReceived/1024 + " Of " + e.TotalBytesToReceive/1024;
this.CurrentProgress = e.ProgressPercentage;
}
private void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.UserState != null && e.UserState is AlisApplicationModel)
{
AlisApplicationModel ObjApp = e.UserState as AlisApplicationModel;
ObjApp.IsDownloaded = true;
}
if (e.Cancelled)
{
this.Cleanup();
}
//if (!_bw.IsBusy)
//{
// _bw.RunWorkerAsync();
//}
}
@whatever什麼原因你下來投票只是給理由,然後downvote – 2015-03-03 08:43:26