設定最大並行線程數

依序處理大量文件或影像可能非常耗時,從而在高容量應用程式中造成瓶頸。 使用平行執行緒可以讓應用程式同時處理多張影像,從而顯著縮短整體執行時間。在本程式碼範例中,我們將示範如何設定IronBarcode以使用多執行緒來加快批次條碼讀取速度。

使用並行線程讀取條碼的五步驟指南

  • 使用IronBarcode;
  • 使用 System.Threading.Tasks;
  • 清單imagePaths = 新的列表() { "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 屬性設為 true 以啟用並行處理。 MaxParallelThreads 屬性也設定為 4,指示讀取器最多使用 4 個並發線程,同時平衡效能和系統資源使用量。

最後,呼叫 Read,傳遞影像路徑清單和配置的選項來檢索 BarcodeResults

學習如何使用IronBarcode設定最大並行線程數

準備好開始了嗎?
Nuget 下載 2,121,847 | 版本: 2026.3 剛剛發布
Still Scrolling Icon

還在捲動嗎?

想要快速證明? PM > Install-Package BarCode
執行範例 看您的字串變成 BarCode。