Our Customers
Contact Us Email: support@barcodelib.com
Home > C# Barcode Reader > How to read barcode in C#? > Read multiple barcodes using C#, Free to Download Trial Package
Download Barcode Reader for .NET Trial

How to scan, read multiple barcodes from image files using C# barcode reader library?

Barcode Reader for .NET is the best .NET / C# barcode image recognition sdk library in the market.
Barcode Reader DLL for C#.NET supports recognize linear & 2d barcode images in:
  • Scan, read all multiple barcodes from a single image file
  • Read, recognize barcodes from bulk image files using C# multi-threading programming
  • Read a single barcode data from image file to improve the scanning speed
  • Support .NET projects on .NET 8, 7, 6, 5, .NET Core and .NET Framework




How to read multiple barcodes from a single image file using C#?

The following text and C# source code will explain how to scan and read all barcodes from a single image file.
  • Call method BarcodeReader.BarcodeReader.ReadBarcode() with image file path and target barcode type specified.
  • Read each BarCode object from the scanned barcode data list, and get barcode data (Code 39 data in the example below)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
            string inputFilePath = "C://Projects//Demo-Files//CODE39_1.png";

            BarCode[] datas = BarcodeReader.BarcodeReader.ReadBarcode(inputFilePath, BarcodeReader.BarcodeReader.CODE39);

            Trace.WriteLine("Total Code 39 barcodes found: " + datas.Length);

            foreach (BarCode barcodeData in datas)
            {
                string data = barcodeData.Data;

                Trace.WriteLine("Code 39 data: " + data);
            }


After running the above C# program, you can find the following message in the output window. There are totally two Code 39 barcodes inside the image file.





How to read barcodes from multiple image files or objects using C# multi-threading?

The text and C# source code below will shwo how to read all multiple image files and scan all barcodes inside using C#.NET multi-reading programming.

  • Define a method scanSingleFile(), which will scan all barcodes from a single input image file
  • In method ReadBarcodesInMultiThread(), we will put each image file in one new thread, and call method scanSingleFile() to get all barcodes from it.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
        private static void ReadBarcodesInMultiThread()
        {
            String[] inputFilePaths = new String[] {
                "C://Projects//Demo-Files//CODE39_1.png",
                "C://Projects//Demo-Files//CODE39_2.png",
                "C://Projects//Demo-Files//CODE39_3.JPG",
                "C://Projects//Demo-Files//CODE39_87654321.jpg" };

            //  Combine all scan results.
            List<String> results = new List<String>();

            try
            {
                    //  Scan each file in a Task.
                System.Threading.Tasks.Task<String[]>[] tasks = new System.Threading.Tasks.Task<String[]>[inputFilePaths.Length];
                for (int i = 0; i < inputFilePaths.Length; i++)
                {
                        tasks[i] = new System.Threading.Tasks.Task<String[]>(
                            (args) => scanSingleFile((Object[])args), new Object[2] { inputFilePaths[i], BarcodeReader.BarcodeReader.CODE39 }
                            );
                        tasks[i].Start();
                }
                //  Wait for all Tasks done.
                System.Threading.Tasks.Task.WaitAll(tasks);

                
                foreach (System.Threading.Tasks.Task<String[]> task in tasks)
                {
                    results.AddRange(task.Result);
                }

             }
             catch (Exception)
             {
                Trace.WriteLine("Error in multi-thread barcode scanning!");
            }

            foreach (String data in results)
            {
                Trace.WriteLine("Code 39 data: " + data);
            }
        }

        private static String[] scanSingleFile(Object[] args)
        {
                try
                {
                    return BarcodeReader.BarcodeReader.read((String)args[0], (int)args[1]);
                }
                catch (Exception)
                {
                    return new String[0];
                }
        }


Run the C# code, you will get totally 5 Code 39 barcode datas, which are displayed in the Vistual Studio .NET output window.






















Also provides .NET Barcode Reader, ASP.NET Barcode Reader, C# Barcode Reader, VB.NET Barcode Reader, .NET QR Code Reader, ASP.NET QR Code Reader, C# QR Code Reader, VB.NET QR Code Reader, .NET Data Matrix Reader, .NET Code 128 Reader, Java Barcode SDK, .NET Barcode SDK, ASP.NET Barcode SDK, Visual C# Barcoding, Visual Basic .NET Barcoding.