Barcode reader and Parallel.For issue

Questions, comments and suggestions concerning VintaSoft Barcode .NET SDK.

Moderator: Alex

Post Reply
Posts: 1
Joined: Mon Nov 26, 2012 11:37 am

Barcode reader and Parallel.For issue

Post by gendalf »

Hello! I try to use your BarcodeReader v7.0, compiled against dotNet 4. I want run parallel recognition of images using Parallel.For, but if I use a single instance of Vintasoft BarcodeReader, that shared between all of my workers, there is NullReferenceException raising from BarcodeReader instance, when BarcodeReader.ReadBarcodes(string) called.
It is not looks like bad synchronization in my code. Are Vintasoft BarcodeReader isntances thread safe? If no, which best practices of instantiation you can recommend to use? How much is costs to create and dispose BarcodeReader instance in each worker routine? Did this class uses unmanaged code and structures?

Code: Select all

void Recognize()
    BarcodeReader reader = new BarcodeReader();
    var files =
        Directory.EnumerateFiles(_baseDirectory, "*.jpg");            
        (file) =>
            var result = reader.ReadBarcodes(file);
            lock (recognitionPages) // recognitionPages is just a System.Collections.Generic.Dictionary<string, IBarcodeInfo[]>
                recognizedPages[file] = result;

static void _setupReader(BarcodeReader reader)
    reader.Settings.ScanDirection =
    ScanDirection.Vertical |
    reader.Settings.ScanBarcodeTypes =
        BarcodeType.Code39 |
    reader.Settings.ExpectedBarcodes = 2;

Site Admin
Posts: 1843
Joined: Thu Jul 10, 2008 2:21 pm

Re: Barcode reader and Parallel.For issue

Post by Alex »


Any instance of the BarcodeReader class is not thread safe and you need use different instances of the BarcodeReader class in different threads.

Best regards, Alexander

Post Reply