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以使用多執行緒來加快條碼批次讀取。

使用平行執行緒讀取條碼的5步驟指南

  • 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天試用金鑰
無需信用卡或帳戶建立