111,092
社区成员




private oid button_click(object sender,EventArgs e)
{
progressBar1.Visible = true;
timer1.Start();
try
{
ItemKit.Common.Class.ImgUpload.UploadProductPic(ref m_UrlList, ProductData.tdProduct[0].ProductCode);//这里是做ftp空间文件上传,运行完这句要等待一段时间(和网络有关。)
progressBar1.Value = 100;
}
catch (Exception ex)
{
MessageBox.Show("图片上传失败!原因:\n" + ex.Message);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value < 100)
{
progressBar1.Value = progressBar1.Value + 1;
}
else
{
timer1.Stop();
}
}
测试过,有效果
但我不知道ItemKit是什么,所以使用一个while(true)代替
private bool m_bExit = false;
private void button1_Click(object sender, EventArgs e)
{
progressBar1.Visible = true;
progressBar1.Maximum = 100;
progressBar1.Value = 0;
System.Threading.ThreadPool.QueueUserWorkItem(fun, null);
try
{
//这里使用死循环代替下面注释的代码
while (!m_bExit)
{
Application.DoEvents();
}
//ItemKit.Common.Class.ImgUpload.UploadProductPic(ref m_UrlList, ProductData.tdProduct[0].ProductCode);//这里是做ftp空间文件上传,运行完这句要等待一段时间(和网络有关。)
progressBar1.Value = 100;
}
catch (Exception ex)
{
MessageBox.Show("图片上传失败!原因:\n" + ex.Message);
}
}
private void fun(object obj)
{
while (true)
{
if (progressBar1.Value >= progressBar1.Maximum)
{
m_bExit=true;
break;
}
Invoke(new MethodInvoker(delegate
{
progressBar1.Value = progressBar1.Value + 1;
}));
System.Threading.Thread.Sleep(10);
}
}
private void button1_Click(object sender, EventArgs e)
{
progressBar1.Visible = true;
progressBar1.Maximum = 100;
progressBar1.Value = 0;
System.Threading.ThreadPool.QueueUserWorkItem(fun, null);
try
{
ItemKit.Common.Class.ImgUpload.UploadProductPic(ref m_UrlList, ProductData.tdProduct[0].ProductCode);//这里是做ftp空间文件上传,运行完这句要等待一段时间(和网络有关。)
progressBar1.Value = 100;
}
catch (Exception ex)
{
MessageBox.Show("图片上传失败!原因:\n" + ex.Message);
}
}
private void fun(object obj)
{
while (true)
{
if (progressBar1.Value >= progressBar1.Maximum)
{
break;
}
Invoke(new MethodInvoker(delegate
{
progressBar1.Value = progressBar1.Value + 1;
}));
System.Threading.Thread.Sleep(10);
}
}