进度栏,计时器,后台工作者在我的Windows应用程序中不起作用 [英] Progress bar , timer, background worker not working in my windows application
问题描述
大家好
我有Windows dot net应用程序,可以在其中捕获图像并将其显示在Picturebox中.
但是捕获后我正在对该图像进行一些处理,这需要一些时间
现在我想在表单底部显示进度条,直到显示图像.
我也使用了背景工作者,但未触发事件:
hi all
i have windows dot net application in which i m capturing image and displaying it in picturebox.
but after capturing i am doing some processing on that image it takes some time
now i want to show progress bar at the bottom of my form until the image is displayed.
i have used background worker also but it is not firing the event:
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
// Set the text.
this.Text = e.ProgressPercentage.ToString();
}
我还使用了进度条计时器,但是该时间在处理图像后被激活.
i have also used the timer for progress bar but that time gets activated after the processing of image.
private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.Value = 10;
}
这是我要从中启动进度栏的功能.
this is my function from which i want to start progress bar.
private void btnCapture_Click(object sender, EventArgs e)
{
//with timer
timer1.Start();
timer1.Interval = 100;
//or with background worker
backgroundWorker1.RunWorkerAsync();
try
{
btnLogIn.Enabled = true;
btnLogOff.Enabled = false;
lblErrorMsg.Text = "";
if (txtUserName.Text != "")
{
savingPath= "C:/Inspira/SSO/SSOImage.bmp";
if (File.Exists(savingPath))
{
File.Delete(savingPath);
}
SSOComp.SSO sosObj = new SSOComp.SSO();
string sucessStatus = sosObj.Capture(savingPath);
if (File.Exists(savingPath))
{
lblErrorMsg.ForeColor = Color.Green;
PicBoxFinger.ImageLocation = savingPath;
//after this i want to stop progress bar .
}
else
{
lblErrorMsg.ForeColor = Color.Red;
lblErrorMsg.Text = "Image not Captutred.";
}
}
else
{
lblErrorMsg.ForeColor = Color.Red;
lblErrorMsg.Text = "Please Enter User Name.";
}
}
catch (Exception ex)
{
lblErrorMsg.Text = ex.Message;
}
}</pre>
和后台工作人员代码:
and background worker code:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 1; i <= 100; i++)
{
// Wait 100 milliseconds.
Thread.Sleep(1000);
// Report progress.
backgroundWorker1.ReportProgress(i+10);
}
}
我想在捕获时启动进度条,直到图片显示在图片框中.
谢谢
上帝保佑大家..
i want to start the progress bar on capture click till the picture is displayed in picturebox.
thank you
god bless u all..
推荐答案
您设置了此属性吗?
Have you set this properties?
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.WorkerSupportsCancellation = true;
这篇关于进度栏,计时器,后台工作者在我的Windows应用程序中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!