我有一个严重的问题。我目前正在做一个补丁程序。
程序中有一个“补丁”按钮,如果用户点击它,下载就开始了。
目前该程序需要下载 5 个文件。下载是正确的,这部分程序正在运行,但是当我点击补丁按钮时,程序开始滞后,我无法关闭,或者改变它的位置。这是代码:
private void button1_Click(object sender, EventArgs e) { Thread thread = new Thread(new ThreadStart(this.download)); 线程.Start(); }
public void download()
{
int downloaded = 0;
int all = 5;
WebClient myWebClient = new WebClient();
if (button1.InvokeRequired)
{
MethodInvoker MethodControll = new MethodInvoker(download);
this.button1.Invoke(MethodControll);
}
else
{
double state;
jelenlegidownload.Text = "alut.dll";
myWebClient.DownloadFile(Files.alutDLL, "alut.dll");
downloaded++;
state = downloaded / all * 100;
progressBar.Value = Convert.ToInt32(state);
progressBar.Refresh();
this.Refresh();
jelenlegidownload.Text = "BlackBox.dll";
myWebClient.DownloadFile(Files.BlackBoxDLL, "BlackBox.dll");
downloaded++;
state = downloaded / all * 100;
progressBar.Value = Convert.ToInt32(state);
progressBar.Refresh();
this.Refresh();
jelenlegidownload.Text = "DevIL.dll";
myWebClient.DownloadFile(Files.DevILDLL, "DevIL.dll");
downloaded++;
state = downloaded / all * 100;
progressBar.Value = Convert.ToInt32(state);
progressBar.Refresh();
this.Refresh();
jelenlegidownload.Text = "fltkdll.dll";
myWebClient.DownloadFile(Files.fltkdllDLL, "fltkdll.dll");
downloaded++;
state = downloaded / all * 100;
progressBar.Value = Convert.ToInt32(state);
progressBar.Refresh();
this.Refresh();
jelenlegidownload.Text = "glut32.dll";
myWebClient.DownloadFile(Files.glut32DLL, "glut32.dll");
downloaded++;
state = downloaded / all * 100;
progressBar.Value = Convert.ToInt32(state);
progressBar.Refresh();
this.Refresh();
文件.cs:
public class Files
{
public static string alutDLL = "https://dl.dropbox.com/s/62tt9w194xefk7t/alut.dll?token_hash=AAHQmybYdR44TRrS9bWQWV7jlZBzZQ-mmmjNy1Kv_qR4cg&dl=1";
public static string BlackBoxDLL = "https://dl.dropbox.com/s/vtdrl8qdpky8p08/BlackBox.dll?token_hash=AAHCtQPBJ5s-3aL5B4FqrmOUIGP6BVvW8ZQeWd-xBzysTw&dl=1";
public static string DevILDLL = "https://dl.dropbox.com/s/spni307vmk4zng9/DevIL.dll?token_hash=AAEmZdQj3dv2NIEh6tcWwkgyJHCytSsX65QXZyNGY2Vl1w&dl=1";
public static string fltkdllDLL = "https://dl.dropbox.com/s/fsa29pelfwgk5ha/fltkdll.dll?token_hash=AAF55SuU_8bfli5gIiPpA-VLWUmZKLbOK-Ys8iokuJ8_XA&dl=1";
public static string glut32DLL = "https://dl.dropbox.com/s/cptiwxv17nhtywp/glut32.dll?token_hash=AAGCNXQPpwrByjp-uG_avBbkNyNjTfOJFxbY3ieNAfLzVw&dl=1";
}
我该如何解决滞后问题?(正如我之前所说,如果我点击“补丁”按钮,文件正在下载,但程序“停止”)