E
Eric Paul
I have searched in vain for what seems like something that should be
simple to accomplish.
I have a Windows application written in C# that scans a driver's
license. While it's scanning I want to display a "Scanning..."
progress bar window until the scanning is complete or the user clicks
cancel.
All is fine as long as I use "form.visible" to display the window with
the progress bar.
I use another thread to display the window and then I kill the thread
when the scanning completes.
The problem is that I want this "progress bar" window to be modal--not
modeless. If I use the "form.showDialog()" all processing stops in the
new thread--the progress bar never updates until the process is
complete.
Is there a way to use a modal window and still continue program
execution?
I have searched and found some references to using "Application.Run()"
and "Form.Invoke" but they're not really very clear on how to
accomplish this. It seems like this problem should have been solved
before since many applications have modal "progress bar" windows but I
can't find any good examples. Here is a sampling of my current code:
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
myScan.Scan();
Byte[] byteBLOBData = new Byte[0];
FileStream fs = new FileStream(ConfigurationSettings.AppSettings["ImageFilename"],
FileMode.Open, FileAccess.Read);
photoBox1.Image= Image.FromStream(fs);
fs.Close();
myScan.ExtractOCRData();
t.Abort();
myScan.ExtractFaceImage();
myScan.ExtractSignature();
if (myScan.ScannerError == false)
{
txtNameOnCard_OCR.Text = myScan.NameOnCard;
txtFirstName_OCR.Text = myScan.FirstName;
txtMiddleName_OCR.Text = myScan.MiddleName;
txtLastName_OCR.Text = myScan.LastName;
txtSuffixName_OCR.Text = myScan.SuffixName;
txtAddress_OCR.Text = myScan.Address;
txtCity_OCR.Text = myScan.City;
txtState_OCR.Text = myScan.State;
txtZip_OCR.Text = myScan.Zip;
txtDOB_OCR.Text = myScan.DOB;
txtIssue_OCR.Text = myScan.Issue;
txtExpires_OCR.Text = myScan.Expires;
txtID_OCR.Text = myScan.ID;
txtAccuracy_OCR.Text = myScan.Accuracy + "";
}
else
{
MessageBox.Show(myScan.ScannerErrorMessage);
myScan.ScannerError = false;
return;
}
public static void ThreadProc()
{
// construct a new progress dialog
frmProgress myProgressDialog = new frmProgress();
myProgressDialog.progressBar1.Minimum = 0;
myProgressDialog.progressBar1.Maximum = 9;
myProgressDialog.progressBar1.Step = 1;
myProgressDialog.progressBar1.Value = 0;
myProgressDialog.FormBorderStyle = FormBorderStyle.FixedDialog;
myProgressDialog.StartPosition = FormStartPosition.CenterScreen;
myProgressDialog.Visible = true;
myProgressDialog.Update();
myProgressDialog.Refresh();
myProgressDialog.CancelButton = myProgressDialog.btnCancel;
while ( myProgressDialog.progressBar1.Value <
myProgressDialog.progressBar1.Maximum )
{
myProgressDialog.progressBar1.Value++;
System.Threading.Thread.Sleep(1000);
myProgressDialog.Update();
myProgressDialog.Refresh();
}
//System.Threading.Thread.Sleep(2500);
myProgressDialog.Visible = false;
}
Any and all suggestions are most welcome.
Thanks,
Eric
simple to accomplish.
I have a Windows application written in C# that scans a driver's
license. While it's scanning I want to display a "Scanning..."
progress bar window until the scanning is complete or the user clicks
cancel.
All is fine as long as I use "form.visible" to display the window with
the progress bar.
I use another thread to display the window and then I kill the thread
when the scanning completes.
The problem is that I want this "progress bar" window to be modal--not
modeless. If I use the "form.showDialog()" all processing stops in the
new thread--the progress bar never updates until the process is
complete.
Is there a way to use a modal window and still continue program
execution?
I have searched and found some references to using "Application.Run()"
and "Form.Invoke" but they're not really very clear on how to
accomplish this. It seems like this problem should have been solved
before since many applications have modal "progress bar" windows but I
can't find any good examples. Here is a sampling of my current code:
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
myScan.Scan();
Byte[] byteBLOBData = new Byte[0];
FileStream fs = new FileStream(ConfigurationSettings.AppSettings["ImageFilename"],
FileMode.Open, FileAccess.Read);
photoBox1.Image= Image.FromStream(fs);
fs.Close();
myScan.ExtractOCRData();
t.Abort();
myScan.ExtractFaceImage();
myScan.ExtractSignature();
if (myScan.ScannerError == false)
{
txtNameOnCard_OCR.Text = myScan.NameOnCard;
txtFirstName_OCR.Text = myScan.FirstName;
txtMiddleName_OCR.Text = myScan.MiddleName;
txtLastName_OCR.Text = myScan.LastName;
txtSuffixName_OCR.Text = myScan.SuffixName;
txtAddress_OCR.Text = myScan.Address;
txtCity_OCR.Text = myScan.City;
txtState_OCR.Text = myScan.State;
txtZip_OCR.Text = myScan.Zip;
txtDOB_OCR.Text = myScan.DOB;
txtIssue_OCR.Text = myScan.Issue;
txtExpires_OCR.Text = myScan.Expires;
txtID_OCR.Text = myScan.ID;
txtAccuracy_OCR.Text = myScan.Accuracy + "";
}
else
{
MessageBox.Show(myScan.ScannerErrorMessage);
myScan.ScannerError = false;
return;
}
public static void ThreadProc()
{
// construct a new progress dialog
frmProgress myProgressDialog = new frmProgress();
myProgressDialog.progressBar1.Minimum = 0;
myProgressDialog.progressBar1.Maximum = 9;
myProgressDialog.progressBar1.Step = 1;
myProgressDialog.progressBar1.Value = 0;
myProgressDialog.FormBorderStyle = FormBorderStyle.FixedDialog;
myProgressDialog.StartPosition = FormStartPosition.CenterScreen;
myProgressDialog.Visible = true;
myProgressDialog.Update();
myProgressDialog.Refresh();
myProgressDialog.CancelButton = myProgressDialog.btnCancel;
while ( myProgressDialog.progressBar1.Value <
myProgressDialog.progressBar1.Maximum )
{
myProgressDialog.progressBar1.Value++;
System.Threading.Thread.Sleep(1000);
myProgressDialog.Update();
myProgressDialog.Refresh();
}
//System.Threading.Thread.Sleep(2500);
myProgressDialog.Visible = false;
}
Any and all suggestions are most welcome.
Thanks,
Eric