.NET CF 2.0: Possible Single Threaded Relocation

A simple application is written in CF 2.0. It is single threaded as far as I know.

Two parts of the application are interesting: an event handler that handles the "barcode scan" event raised by a class that represents the PDA barcode scanner (provided by the manufacturer), and an event handler for Windows.Forms.Timer that fires every 30 seconds.

The application has been suffering from a bug lately, the only possible cause of which I can see is handling the line scan event right in the middle of the Timer_Tick event. I was absolutely convinced that this was not possible and that one of the events would wait in the queue until the first was fully processed. The Windows.Forms.Timer page on MSDN also ensures that this is a normal single-threaded timer. Barcode initiated code. Scanned changes to some parts of the interface that don't throw an exception, so I'm assuming it's single-threaded. No, we are not using DoEvents, etc.

Can anyone tell me that such re-engagement is not possible and I should look for other possible reasons, or vice versa, that they suffered from the same problem?

0


source to share


2 answers


The Windows.Forms timer will occur on the UI thread through a call to PostMessage. This is a guarantee. How "the barcode is scanned" is even included is entirely up to the developer of the library that gives you the event. You should, of course, not assume that it will run in the same context as your timer, unless you specifically enforce it (via a call to Control.Invoke). Even with that, I don't believe you can guarantee a challenge order.



If you think reconnection may be the cause, the solution is relatively simple - use a monitor in both handlers (proc timer and event) and lock it on the same object. This will eliminate the possibility that it is a return issue. If the problem goes away, you know the cause and already have a fix. If the problem persists, you probably know that this is not a reentraction and you can focus elsewhere.

+1


source


Pretty much every barcode scanning component I've worked with works with a background thread, so I'd take a closer look at this.



0


source







All Articles