我正在尝试获取更新表单。
当有更新的文件并使用edtFTPNet
下载时,我使用库来打开表单在我传递FTP对象并开始下载的表单中,在FormLoad中我处理两个事件,并使用Thread to StartDownload()。我的两个事件从未调用过,我用它来设置进度条。
public partial class UpdateProgressForm : XtraForm
{
public FTPConnection FtpConn { get; set; }
public string UpdateFileName { get; set; }
public UpdateProgressForm()
{
InitializeComponent();
}
private void OnLoad(object sender, EventArgs e)
{
FtpConn.Downloading += FileDownLoading;
FtpConn.BytesTransferred += FileBytesTransfered;
}
private void FileDownLoading(object sender, FTPFileTransferEventArgs e)
{
progressBar.Properties.Maximum = (int) e.FileSize;
}
private void FileBytesTransfered(object sender, BytesTransferredEventArgs e)
{
progressBar.Position = (int) e.ByteCount;
}
public void StartDownload()
{
FtpConn.DownloadFile(@".\" + UpdateFileName, UpdateFileName);
}
private void OnShown(object sender, EventArgs e)
{
Thread tt = new Thread(StartDownload) {IsBackground = true};
tt.Start();
}
}
调用表单的库方法:
private void DownloadUpdateFile(string updateFileName)
{
using (ProgressForm = new UpdateProgressForm { FtpConn = FtpConn, UpdateFileName = updateFileName })
{
ProgressForm.ShowDialog();
}
}
有任何帮助吗?谢谢。
答案 0 :(得分:0)
您确定没有调用事件处理程序吗?我认为您的问题是您尝试更新调用事件处理程序的工作线程上的进度条(这不是创建GUI的线程)。您应该确保在正确的线程上执行GUI更新:
private void FileDownLoading(object sender, FTPFileTransferEventArgs e)
{
progressBar.Invoke((MethodInvoker) delegate
{
progressBar.Properties.Maximum = (int) e.FileSize;
});
}
答案 1 :(得分:0)