System.IO.Ports Reading COM Port (Scanner) and throwing eve

Posted by Stefan Marquardt on 18-Apr-2012 09:53


in our cashbase project we are using OPOS driver for printing and scanning.

The methods from the OPOS model are only a handful and POS for .NET 1.12 seems to be dead (no 64bit and .NET 4 version).

I decided to change the communication from OPOS to serial.

Since today i never did asynchron serial communication and wrote a small C# testcode using System.IO.Ports

In C# i noticed that the Event DataReceived isn't threadsafe and wrote a delegate. (without my small app was hanging)

.NET docu:

The DataReceived event is raised on a secondary thread when data is received from the SerialPort object. Because this event is raised on a secondary thread, and not the main thread, attempting to modify some elements in the main thread, such as UI elements, could raise a threading exception. If it is necessary to modify elements in the main Form or Control, post change requests back using Invoke, which will do the work on the proper thread.

Is it correct that with ABL.NET multithreading isn't still possible?
I need a Delegate and the method Invoke, without the application will crash because the UI is running in another thread.
Is this possible with ABL.NET (11.0) ?

This is a part of my code:

public delegate void AddListItem(string myString);

public AddListItem myDelegate;

myDelegate =

new AddListItem(AddListItemMethod);

void _serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)


string barcode;

barcode = _serialPort.ReadLine().TrimEnd();

this.Invoke(this.myDelegate, new object[] { barcode });


_serialPort.DataReceived +=

new SerialDataReceivedEventHandler(_serialPort_DataReceived);


All Replies

Posted by Admin on 18-Apr-2012 10:27

Is it correct that with ABL.NET multithreading isn't still possible?

Yes, nothing changed in OE11.0

You'll have to deal with the background thread in a custom .NET Assembly and raise the event in the foreground thread - some Infragistics Controls do this to speed up initialization and don't crash the AVM. So it's possible.

Posted by PeterWokke on 27-Nov-2015 03:11

Can you specify which Infragistics Controls are you referring to?

We have the Ultra Controls supplied by Progress and I really need to be able to get events from bar-code readers in my application.


This thread is closed