IRONSOFTWAREHOME

How to Use Async and Multithread in C# with IronBarcode

Hairil Hasyimi Bin Omar
Hairil Hasyimi Bin Omar
Updated: August 2, 2026

Async and multithreading in IronBarcode optimize barcode reading performance differently - async prevents blocking the main thread during I/O operations while multithreading processes multiple barcodes simultaneously across CPU cores.

Developers often confuse Async and Multithreading operations. Both methods enhance program performance and efficiency by optimizing system resource utilization and reducing runtime. However, they differ in approach, mechanisms, and use cases. IronBarcode supports both approaches. This article explores their differences and implementation using IronBarcode.

Quickstart: Async & Multithreaded Barcode Reading Example

Use this one-line example to get started instantly with IronBarcode. It shows how easy it is to combine asynchronous reading and multithreading options to scan multiple barcode images in parallel with minimal setup.

  1. 1Install IronBarcode with NuGet Package Manager

    PM > Install-Package BarCode

  2. 2Copy and run this code snippet.

    var results = await IronBarCode.BarcodeReader.ReadAsync(imagePaths, new IronBarCode.BarcodeReaderOptions { Multithreaded = true, MaxParallelThreads = 4, ExpectMultipleBarcodes = true });
    C#
  3. 3Deploy to test on your live environment

    Start using IronBarcode in your project today with a free trial
    arrow pointer

How Do I Read Barcodes Asynchronously with IronBarcode?

Asynchronous reading enables long or blocking operations to proceed without blocking the main thread's execution. In C#, use the async and await keywords with methods supporting asynchronous features. This approach doesn't create additional threads but releases the current thread. While the main thread initiates and manages tasks, it doesn't remain exclusively devoted to a single task. The main thread returns when the asynchronous method requires its involvement, freeing it to handle other tasks when not needed - particularly useful for I/O-bound tasks like reading/writing files or making network requests.

Consider barcode reading as an example. The process involves:

  • Reading the file
  • Applying reading options
  • Decoding the barcode

During file reading, the main task can be released. This benefits scenarios with multiple image files or large PDFs, as demonstrated in our reading barcodes tutorial.

Use ReadAsync and ReadPdfsAsync methods to read barcodes asynchronously for images and PDF documents, respectively. Before implementing async operations, ensure you've installed IronBarcode via NuGet in your project.

using IronBarCode;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

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

// Barcode reading options
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
    ExpectMultipleBarcodes = true
};

// Read barcode using Async
BarcodeResults asyncResult = await BarcodeReader.ReadAsync(imagePaths, options);

// Print the results to console
foreach (var result in asyncResult)
{
    Console.WriteLine(result.ToString());
}

The code snippet above instantiates a List of image paths to be read asynchronously by IronBarcode. To read the images, use the ReadAsync method from the BarcodeReader class. Specify the imagePaths and reading options. For advanced configuration options, refer to our guide on barcode reader settings.

This asynchronous operation method is also available for reading barcodes in PDF documents through ReadPdfsAsync in the same class. For specific PDF reading configurations, see our PDF barcode reader settings guide.

Multithreaded
MaxParallelThreads

When Should I Use Async Reading Over Regular Methods?

Asynchronous reading excels in several scenarios:

  1. GUI Applications: Windows Forms or WPF applications requiring UI responsiveness. Async prevents interface freezing during barcode scanning.
  2. Web Applications: ASP.NET applications handling multiple concurrent requests without blocking threads, especially when processing uploaded barcode images.
  3. Batch Processing: Sequential reading of multiple barcode images or PDFs, allowing other tasks to execute during I/O operations.
  4. Network Operations: Reading barcodes from remote sources or URLs, as shown in our read barcodes from URL asynchronously example.

Why Does Async Reading Improve Application Responsiveness?

Asynchronous reading improves responsiveness by freeing the main thread during I/O-bound operations. When IronBarcode reads an image file from disk or processes a PDF, the thread doesn't wait idle. Instead, it handles other tasks like responding to user input or processing requests. This is especially noticeable when dealing with:

  • Large image files requiring significant load time
  • PDFs with multiple pages containing barcodes
  • Network-based image sources
  • Scenarios requiring image correction filters before barcode detection

What Are Common Pitfalls When Using Async Barcode Reading?

When implementing async barcode reading, watch for these common issues:

  1. Deadlocks: Avoid Result or Wait() on async methods in UI contexts. Always use await throughout the call chain.
  2. Exception Handling: Wrap async calls in try-catch blocks as exceptions in async methods may not propagate as expected.
  3. Context Switching: Consider ConfigureAwait(false) usage when you don't need to return to the original synchronization context.
  4. Performance Misconceptions: Async doesn't accelerate individual operations; it improves application responsiveness. For speed improvements with multiple images, consider multithreading.

For troubleshooting async-related issues, consult our barcode recognition troubleshooting guide.

How Do I Enable Multithreaded Barcode Reading?

Unlike asynchronous operations, multithreading executes a single process across multiple threads simultaneously. Instead of sequential execution in a single thread, multithreading divides tasks among multiple threads for concurrent execution. Multithreading requires multiple CPU cores, as these cores independently execute threads. Like asynchronous operations, multithreading enhances application performance and responsiveness.

In IronBarcode, enable multithreading by setting the Multithreaded property and specifying maximum cores for concurrent execution using MaxParallelThreads in BarcodeReaderOptions. The default MaxParallelThreads value is 4, adjustable based on available CPU cores. For optimal performance configurations, see our reading speed options guide.

Please note: To find available cores: Task Manager -> Performance tab -> Click CPU. 'Cores' field displays count.
using IronBarCode;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

List<string> imagePaths = new List<string>(){"test1.jpg", "test2.png"};

// Barcode reading options
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
    Multithreaded = true,
    MaxParallelThreads = 4,
    ExpectMultipleBarcodes = true
};

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

// Print the results to console
foreach (var result in results)
{
    Console.WriteLine(result.ToString());
}

How Much Performance Improvement Can I Expect?

Let's read two sample images and compare reading times across normal, asynchronous, and multithreaded operations.

Sample Image

UPC-A barcode example showing number 0 123456 789012 for multithread barcode reading demonstration
UPC-A barcode sample showing number 771234567003 for multithread barcode reading demonstration
Normal ReadAsynchronous ReadMultithreaded Read (4 cores)
01.75 seconds01.67 seconds01.17 seconds

The comparison shows performance increases with asynchronous and multithreaded reading. In this illustrative example, multithreading provides a notable improvement over normal reading, while async delivers a smaller improvement; actual results vary by hardware, dataset, and IronBarcode version. However, these operations serve different purposes and approaches. Choose the approach that best suits your application requirements.

Performance improvements vary based on:

  • Number of images processed
  • Image complexity and barcode quality
  • Available CPU cores
  • Other system resources

For situations with multiple barcodes on a single document, visit the Read Multiple Barcodes guide.

When Should I Choose Multithreading Over Async Operations?

Choose multithreading when:

  1. CPU-Bound Operations: Processing involves heavy computation like complex image filters or high-resolution images
  2. Batch Processing: Multiple independent images require simultaneous processing
  3. Multi-Core Systems: Deployment environment has multiple CPU cores available
  4. Performance Critical: Raw processing speed outweighs resource efficiency

Choose async operations when:

  1. I/O-Bound Operations: Most time involves reading files or waiting for network responses
  2. UI Applications: Maintaining responsive user interfaces is crucial
  3. Limited Resources: Running on systems with limited CPU cores
  4. Web Applications: Handling multiple concurrent requests efficiently

How Do I Determine the Optimal MaxParallelThreads Value?

The optimal MaxParallelThreads value depends on several factors:

  1. Available CPU Cores: Start with Environment.ProcessorCount as baseline
  2. Workload Type: For pure barcode reading, use 75% of available cores
  3. System Resources: Leave headroom for OS and other processes
  4. Testing Results: Benchmark with your specific workload

Here's a practical approach to finding the optimal value:

int optimalThreads = Math.Max(1, Environment.ProcessorCount - 1);

For production environments, monitor performance and adjust based on actual usage patterns. Consider implementing license key configuration for enterprise deployments requiring maximum performance.

For complete API capabilities, consult the IronBarcode API Reference.

Frequently Asked Questions

What is async barcode reading in C#?

Asynchronous barcode reading in C# with IronBarcode allows barcode scanning to proceed without blocking the main thread during I/O operations. This is useful for operations involving file reading or network requests. Methods like 'ReadAsync' in IronBarcode facilitate this by using 'async' and 'await' keywords.

How does multithreading improve barcode reading performance in IronBarcode?

Multithreading improves barcode reading performance by employing multiple threads to process images simultaneously across CPU cores. In IronBarcode, this feature is enabled by setting the 'Multithreaded' property and specifying 'MaxParallelThreads' in 'BarcodeReaderOptions'.

Can I use both async and multithreading for barcode reading in IronBarcode?

Yes, IronBarcode supports the combination of asynchronous reading and multithreading. This allows for efficient processing of multiple barcode images by utilizing async/await for non-blocking I/O and multithreading to leverage CPU cores for parallel processing.

When should I prefer async barcode reading over multithreaded operations?

Async reading should be preferred in scenarios where I/O-bound operations are predominant, such as reading files or managing network requests. It is also beneficial in applications where maintaining responsiveness, such as GUI and web applications, is crucial.

What are some common pitfalls when using async barcode reading?

Common pitfalls include deadlocks when using 'Result' or 'Wait' instead of 'await', insufficient exception handling, unnecessary context switching, and performance misconceptions where async is expected to accelerate individual operations.

What factors affect the optimal 'MaxParallelThreads' setting in IronBarcode?

The optimal 'MaxParallelThreads' value is influenced by available CPU cores, workload type, overall system resources, and testing results. A practical starting point is to use one less than the total available CPU cores.

How does IronBarcode's async functionality improve application responsiveness?

Async functionality in IronBarcode increases application responsiveness by freeing the main thread during long I/O-bound barcode reading tasks, allowing the application to handle other processes concurrently, such as user interface updates.

What are the advantages of using multithreading in barcode reading?

Multithreading allows simultaneous processing of multiple images, which enhances performance in CPU-bound operations such as processing complex image filters or high-resolution images. This is beneficial in environments with multiple CPU cores.

How can I implement license key configuration for optimal performance in IronBarcode?

For enterprise deployments requiring maximum performance, consider implementing license key configuration. This can be done by following IronBarcode's documentation on license key settings to fully unlock features and optimize resource utilization.

What are the key differences between async and multithreading in IronBarcode?

Async in IronBarcode prevents blocking the main thread during I/O operations, ideal for file and network tasks, whereas multithreading divides tasks among threads for concurrent execution across CPU cores, improving performance in CPU-bound operations.

Ready to Get Started?

Nuget Downloads 2,422,100Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package BarCode
nuget.org/packages/BarCode/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronBarCode"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronBarCode to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronBarCode.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required