1
here it is:
Action<int, ProgressBar, Label, Label, int, Button> downloadFileAsync = (i, pb, label2, label1, ServID, button1) =>
{
var bd = AppDomain.CurrentDomain.BaseDirectory;
var fn = bd + "/" + i + ".7z";
var down = new WebClient();
DownloadProgressChangedEventHandler dpc = (s, e) =>
{
label1.Text = "Download Update: " + i + " From: " + ServID;
int rec =Convert.ToInt16(e.BytesReceived/1024);
int total =Convert.ToInt16(e.TotalBytesToReceive/1024) ;
label2.Text = "Downloaded: " + rec.ToString() + "/" + total.ToString() + " KB";
pb.Value = e.ProgressPercentage;
};
AsyncCompletedEventHandler dfc = null; dfc = (s, e) =>
{
down.DownloadProgressChanged -= dpc;
down.DownloadFileCompleted -= dfc;
CompressionEngine.Current.Decoder.DecodeIntoDirectory(AppDomain.CurrentDomain.BaseDirectory + "/" + i + ".7z", AppDomain.CurrentDomain.BaseDirectory);
File.Delete(fn);
if (i == ServID)
{
button1.Enabled = true;
label1.Text = "Game Is Up-To-Date.Have Fun!!";
label2.Text = "Done..";
}
down.Dispose();
};
現在我唯一的問題是,當程序解壓下載的文件行動<>,等待一個額外的動作來完成
CompressionEngine.Current.Decoder.DecodeIntoDirectory(AppDomain.CurrentDomain.BaseDirectory + "/" + i + ".7z", AppDomain.CurrentDomain.BaseDirectory);
在一些文件,它需要時間來解壓下載的文件 所以我如何告訴程序等待解壓縮完成? (我使用BackgroundWorker)
工作完成時,後臺工作引發的事件。您是否嘗試過將事件處理程序附加到該事件? –
是的,我做到了。 問題是背景工作者在curret文件下載完成之前完成 –