public void progressChanged(ProgressEvent progressEvent) { int eventCode = progressEvent.getEventCode(); if (eventCode == ProgressEvent.STARTED) { Console.WriteLine("Started."); } else if (eventCode == ProgressEvent.COMPLETED) { Console.WriteLine("Completed."); } else if (eventCode == ProgressEvent.FAILED) { Console.WriteLine("Failed."); } else if (eventCode == ProgressEvent.CANCELED) { Console.WriteLine("Cancled."); } else if (eventCode == ProgressEvent.TRANSFERRED) { this.completedSize += progressEvent.getBytesTransferred(); int newRate = (int)((double)completedSize / size * 100 + 0.5); if (newRate > this.rate) { this.rate = newRate; Console.WriteLine("Processing ... " + this.rate + "%"); } } } // end of progressChanged
/** * 实现的ProgressListener的接口,处理IO线程反馈回来的消息 */ public void progressChanged(ProgressEvent progressEvent) { /** * 用线程安全的方式重绘界面 */ if (this.resultLabel.InvokeRequired) { this.Invoke(new ProgressChangedHandler(progressChanged), new object[] { progressEvent }); return; } int eventCode = progressEvent.getEventCode(); if (eventCode == ProgressEvent.STARTED) { this.resultLabel.Text = "正在进行中"; } else if (eventCode == ProgressEvent.COMPLETED) { this.resultLabel.Text = "已完成"; this.cancleBtn.Enabled = false; this.completeBtn.Enabled = true; this.ks3Browser.loadObjectList(); } else if (eventCode == ProgressEvent.FAILED) { this.resultLabel.Text = "已失败"; this.cancleBtn.Enabled = false; this.completeBtn.Enabled = true; } else if (eventCode == ProgressEvent.CANCELED) { this.resultLabel.Text = "已取消"; this.cancleBtn.Enabled = false; this.completeBtn.Enabled = true; } else if (eventCode == ProgressEvent.TRANSFERRED) { this.completedSize += progressEvent.getBytesTransferred(); long x = this.completedSize; if (scale > 1) { x = (long)((double)x / scale + 0.5); } this.progressBar.Value = (int)x; } }