显示Time倒计时
int DownloadTime =0;
private void btnSave_Click(object sender, System.EventArgs e)
{
this.timer1.Enabled = true;
byte[] inf = WebServer.NewObject.GetUser();
System.Text.Encoding ed = System.Text.Encoding.GetEncoding("GBK");
string s = ed.GetString(inf, 0, inf.Length);
string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName) + "\\s_user.txt";
FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding("GBK"));
sw.WriteLine(s);
sw.Close();
fs.Close();
this.timer1.Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
this.lblNews.Text = "正在下载用户信息,请等待..." + DownloadTime;
DownloadTime += 1;
// this.Refresh();
}
通过WebService下载数据,然后写入TXT里面。应该数据有上万条,所以大概需要时间30秒。
在写入TXT文本的时候,我想在界面上给一个提示。所以在点击Button时启动Time控件,写入完成就关闭Time控件。 现在问题是,程序在写入文本时会停在那,不会进入Time事件。 怎么让在写入文本时,Time事件也在运行呢?
[解决办法]
backgroundworker 写错了 不好意思