我是在做邮件的收与发,在接收的时候,用个进度条来表示它的接收进度,当进度等于一百的时候,启动一个Timer控件,进行3秒钟倒计时,然后自动关闭这个接收窗体(我这是用WinForm搞的)!可是就是没有效果!更诡异的是上边那句被注掉的MessageBox.Show("接收完毕!"); 一写上,让对话框弹出来,这个时钟控件就起作用,当把对话框窗体上的"确定"一单击,时钟控件马上就停了,如果没有那句代码,时钟控件压根就不起作用.这是为什么?有哪个高手帮帮忙!急! 还有,上边的代码是写在线程调用的方法里的
string StrEmailReceive = ReceiveState();
lbReceiveMessage.Text = StrEmailReceive;
//切割接收到的信息
string[] StrCountReceive = StrEmailReceive.Split(' ');
//获取邮件一共有多少封
int CountEmail = Convert.ToInt32(StrCountReceive[1]);
//判断邮件一共有多少封
if (CountEmail > 0)
{
panelProgressBar.Visible = true;
//总进度条的最小值
progressBarCount.Minimum = 0;
//总进度条的最大值
progressBarCount.Maximum = CountEmail;
for (int i = 1; i <= CountEmail; i++)
{
//向接收邮件服务器发送命令,查看邮件
SendMessage("RETR " + i);
//定义变量用于接收POP3邮件服务器返回的信息
string MyReceiveMessage = "";
//接收POP3邮件服务器返回的信息
MyReceiveMessage = ReceiveState(); //以\r\n.\r\n做标识判断是否将邮件内容接收完毕,没有接收完则循环接收
while (MyReceiveMessage.IndexOf("\r\n.\r\n") < 0)
{
MyReceiveMessage += ReceiveState();
}
//总进度的当前值
progressBarCount.Value = i;
//总进度的百分数
lbProgressBar.Text = (progressBarCount.Value * 100) / CountEmail + "%";
if (lbProgressBar.Text == "100%")
{ lbTime.Visible = true;
lbCutTime.Visible = true;
timer1.Enabled = true;
//MessageBox.Show("接收完毕!");
} }
}
#region 计时器
int i = 3;
private void timer1_Tick(object sender, EventArgs e)
{
int k = i--;
lbTime.Text = k.ToString();
if (lbTime.Text == "0")
{
timer1.Enabled = false;
this.Close();
}
}
#endregion
string StrEmailReceive = ReceiveState();
lbReceiveMessage.Text = StrEmailReceive;
//切割接收到的信息
string[] StrCountReceive = StrEmailReceive.Split(' ');
//获取邮件一共有多少封
int CountEmail = Convert.ToInt32(StrCountReceive[1]);
//判断邮件一共有多少封
if (CountEmail > 0)
{
panelProgressBar.Visible = true;
//总进度条的最小值
progressBarCount.Minimum = 0;
//总进度条的最大值
progressBarCount.Maximum = CountEmail;
for (int i = 1; i <= CountEmail; i++)
{
//向接收邮件服务器发送命令,查看邮件
SendMessage("RETR " + i);
//定义变量用于接收POP3邮件服务器返回的信息
string MyReceiveMessage = "";
//接收POP3邮件服务器返回的信息
MyReceiveMessage = ReceiveState(); //以\r\n.\r\n做标识判断是否将邮件内容接收完毕,没有接收完则循环接收
while (MyReceiveMessage.IndexOf("\r\n.\r\n") < 0)
{
MyReceiveMessage += ReceiveState();
}
//总进度的当前值
progressBarCount.Value = i;
//总进度的百分数
lbProgressBar.Text = (progressBarCount.Value * 100) / CountEmail + "%";
if (lbProgressBar.Text == "100%")
{ lbTime.Visible = true;
lbCutTime.Visible = true;
timer1.Enabled = true;
//MessageBox.Show("接收完毕!");
} }
}
#region 计时器
int i = 3;
private void timer1_Tick(object sender, EventArgs e)
{
int k = i--;
lbTime.Text = k.ToString();
if (lbTime.Text == "0")
{
timer1.Enabled = false;
this.Close();
}
}
#endregion
这句话导致的,这句话的条件不满足所以由你说的情况发生。