设置最大并行线程

按顺序处理大量文档或图像可能非常耗时,从而在高容量应用程序中造成瓶颈。 使用并行线程可以让应用程序同时处理多张图像,从而显著缩短整体执行时间。在本代码示例中,我们将演示如何配置 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

学习如何使用IronBarcode设置最大并行线程

准备开始了吗?
Nuget 下载 2,317,217 | 版本: 2026.7 刚刚发布
Still Scrolling Icon

还在滚动吗?

想快速获得证据? PM > Install-Package BarCode
运行示例 观看您的字符串变成 BarCode。