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.
privatestaticvoidReadBarcodesInMultiThread(){String[]inputFilePaths=newString[]{"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=newList<String>();try{// Scan each file in a Task.System.Threading.Tasks.Task<String[]>[]tasks=newSystem.Threading.Tasks.Task<String[]>[inputFilePaths.Length];for(inti=0;i<inputFilePaths.Length;i++){tasks[i]=newSystem.Threading.Tasks.Task<String[]>((args)=>scanSingleFile((Object[])args),newObject[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[]>taskintasks){results.AddRange(task.Result);}}catch(Exception){Trace.WriteLine("Error in multi-thread barcode scanning!");}foreach(Stringdatainresults){Trace.WriteLine("Code 39 data: "+data);}}privatestaticString[]scanSingleFile(Object[]args){try{returnBarcodeReader.BarcodeReader.read((String)args[0],(int)args[1]);}catch(Exception){returnnewString[0];}}
Run the C# code, you will get totally 5 Code 39 barcode datas, which are displayed in the Vistual Studio .NET output window.