设置最大并行线程
按顺序处理大量文档或图像可能非常耗时,从而在高容量应用程序中造成瓶颈。 使用并行线程可以让应用程序同时处理多张图像,从而显著缩短整体执行时间。在本代码示例中,我们将演示如何配置 IronBarcode 以使用多线程来加快批量条形码读取速度。
使用并行线程读取条形码的五步指南
using IronBarCode;using System.Threading.Tasks;List<string> imagePaths = new List<string>() { "sample_a.png", "sample_b.png" };BarcodeReaderOptions options = new BarcodeReaderOptions(){ Multithreaded = true, MaxParallelThreads = 4 };BarcodeResults results = BarcodeReader.Read(imagePaths, options);
代码解释
首先,导入IronBarcode库和线程命名空间,并定义一个包含待处理图像路径的List<string>。 在上面的示例中,"sample_a.png"和"sample_b.png"已准备好进行扫描。
接下来,实例化一个BarcodeReaderOptions对象以配置扫描行为。 Multithreaded 此外,将ParallelProcessing属性设置为true以启用并行处理。 Multithreaded 还将MaxDegreeOfParallelism属性设置为4,指导读取器使用最多4个同时线程,同时在性能与系统资源使用之间取得平衡。 MaxParallelThreads MaxParallelThreads Read BarcodeReader.Read
最后,调用BarcodeResults。

