IRONSOFTWAREHOME
设置最大并行线程
using IronBarCode;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

List<string> imagePaths = new List<string>() { "sample_a.png", "sample_b.png" };

// Barcode reading options
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
    // Set Max threads to 4
    Multithreaded = true,
    MaxParallelThreads = 4,
};

// Read barcode with multithreaded enabled
BarcodeResults results = BarcodeReader.Read(imagePaths, options);

Imports IronBarCode
Imports System
Imports System.Collections.Generic
Imports System.Threading.Tasks

Dim imagePaths As New List(Of String)() From {"sample_a.png", "sample_b.png"}

' Barcode reading options
Dim options As New BarcodeReaderOptions() With {
    .Multithreaded = True,
    .MaxParallelThreads = 4
}

' Read barcode with multithreaded enabled
Dim results As BarcodeResults = BarcodeReader.Read(imagePaths, options)
NuGet Download
PM > Install-Package BarCode
设置最大并行线程

设置最大并行线程

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

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户