所以基本上我想在互联网上检索 .txt 文件的内容并将其写入 aa 标签。但是,尽管这样做,Windows 窗体会冻结。
所以我想把它放到一个BackgroundWorker中。还有一个进度条,应该在进度期间填充。我的代码如下所示:
private void RetrieveTxt(string currentversion)
{
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
WebClient wc = new WebClient();
label1.Text = wc.DownloadString("http://example.org/version.txt");
}
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
updateProgress.Value = e.ProgressPercentage;
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
updateProgress.Visible = false;
}
但是,它不起作用。标签永远不会更新,进度条保持空白。
任何帮助表示赞赏,谢谢!:)