I invoke a "Find" form from FrmDelivery. The Find form is crashing on attempting to scan a barcode into an editbox (the same code works fine elsewhere in the app, such as in FrmDelivery).
The log file shows that FrmDelivery is the form experiencing an exception:
Message: Reached frmDelivery.StartRead
Date: 2/19/2015 7:39:39 PM
Message: From FrmDelivery.StartRead(): The scanner not enabled, Call Enable() first.; Inner Ex: ; Stack Trace: at
Symbol.Barcode.Actions.Read(ReaderData rd)
Yet, prior to opening the Find form, I close FrmDelivery ("this" below):
private void buttonFind_Click(object sender, EventArgs e)
{
ExceptionLoggingService.Instance.WriteLog("Reached frmDelivery.buttonFind_Click");
this.Close(); // Close the Delivery form; this still leaves frmMain up
const HHSConsts.RecordTypes rt = HHSConsts.RecordTypes.Delivery;
frmFind ff = new frmFind(rt, dsdName);
ff.ShowDialog();
}
StartRead() is the method throwing the exception:
private void StartRead()
{
ExceptionLoggingService.Instance.WriteLog("Reached
frmDelivery.StartRead");
try
{
// If we have both a reader and a reader data
if ((this.barcodeReader != null) && (this.barcodeReaderData !=
null))
{
if (this.barcodeReaderData.IsPending) return;
// Submit a read
this.barcodeReader.ReadNotify += this.barcodeEventHandler;
this.barcodeReader.Actions.Read(this.barcodeReaderData);
}
}
catch (Exception ex)
{
String msgInnerExAndStackTrace = String.Format(
"{0}; Inner Ex: {1}; Stack Trace: {2}", ex.Message,
ex.InnerException, ex.StackTrace);
ExceptionLoggingService.Instance.WriteLog(String.Format("From
FrmDelivery.StartRead(): {0}", msgInnerExAndStackTrace));
}
}
// StartRead() is called four places in FrmDelivery:
private void textBoxUPC_PLU_GotFocus(object sender, EventArgs e)
{
textBoxUPC_PLU.BackColor = HHSConsts.BARSCAN_COLOR; // Why is this
not sticking?
ExceptionLoggingService.Instance.WriteLog("Reached
frmDelivery.textBoxUPC_PLU_GotFocus");
if (this.InitReader())
{
this.StartRead();
}
}
private void BarcodeReader_ReadNotify(object sender, EventArgs e)
{
ExceptionLoggingService.Instance.WriteLog("Reached
frmDelivery.BarcodeReader_ReadNotify");
try
{
Symbol.Barcode.ReaderData TheReaderData =
this.barcodeReader.GetNextReaderData();
if (TheReaderData.Result == Symbol.Results.SUCCESS)
{
// Handle the data from this read
this.HandleData(TheReaderData);
// Start the next read
this.StartRead();
}
}
catch (Exception ex)
{
String msgInnerExAndStackTrace = String.Format(
"{0}; Inner Ex: {1}; Stack Trace: {2}", ex.Message,
ex.InnerException, ex.StackTrace);
ExceptionLoggingService.Instance.WriteLog(String.Format("From
FrmDelivery.BarcodeReader_ReadNotify(): {0}",
msgInnerExAndStackTrace));
}
}
private void ReaderForm_Activated(object sender, EventArgs e)
{
ExceptionLoggingService.Instance.WriteLog("Reached
frmDelivery.ReaderForm_Activated");
// If there are no reads pending on barcodeReader, start a new read
if (!this.barcodeReaderData.IsPending)
{
this.StartRead();
}
}
private void textBoxId_GotFocus(object sender, EventArgs e)
{
ExceptionLoggingService.Instance.WriteLog("Reached
frmDelivery.textBoxId_GotFocus");
if (this.InitReader())
{
this.StartRead();
}
}
But how could any of these methods call StartRead() after the form has been closed?