从条形码数据输入处理程序启用/禁用扫描程序时出现NullPointerException

时间:2013-09-12 20:59:56

标签: c# .net .net-3.5 barcode-scanner windows-mobile-6

我正在为摩托罗拉条码扫描仪开发,看起来我有一些线程问题。当我将barcode_OnRead()设置为来自扫描仪的输入处理程序并在同一流程中操纵扫描仪的状态时,我很快就会得到NullPointerException。例如,这将导致问题:

private void barcode_OnRead(object sender, Symbol.Barcode.ReaderData readerData)
{
  this.barcode.EnableScanner = false;
}

在我看来,这似乎是一个线程问题,但我对C#并不十分精通,我不知道如何在不同的线程(例如UI线程)上运行......

修改 仅上面的代码就会触发问题。 this.barcode当时不是null。 来自异常的堆栈跟踪:

at Barcode.Barcode.SetScanParameters()
at Barcode.Barcode.Reader_ReadNotify(Object sender, EventArgs e)
at System.Windows.Forms.Control.TASK.Invoke()
at System.Windows.Forms.Control._InvokeAll()
at System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
at System.Windows.Forms.Application.Run(Form fm)
at AppName.Program.Main()

0 个答案:

没有答案