How to use Async and Multithreading in C# | IronOCR

C# Async & Multithreading Support with IronOCR

IronOCR automatically handles multithreading across all CPU cores and provides async methods like ReadAsync() to perform OCR without blocking your main thread, ensuring responsive applications while processing large documents.

Introduction

Processing large volumes of text data efficiently requires both accuracy and speed for OCR operations. This article covers async support and multithreading in IronOCR and Tesseract. Asynchronous programming enables non-blocking OCR execution, keeping applications responsive during text recognition tasks. Multithreading provides parallelism to significantly boost OCR performance. These techniques help developers improve the efficiency and responsiveness of OCR-powered applications.

Quickstart: Use ReadAsync for Effortless Async OCR

Use IronTesseract's ReadAsync method to perform OCR without blocking your main thread. This quickly adds responsive, non-blocking OCR to your application. It works particularly well when processing PDF documents or handling multiple image files simultaneously.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. Copy and run this code snippet.

    var result = await new IronOcr.IronTesseract().ReadAsync("image.png");
  3. Deploy to test on your live environment

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

How Does Multithreading Work in IronOCR?

IronOCR enhances image processing and OCR reading efficiency through seamless multithreading, requiring no specialized API from developers. IronTesseract automatically leverages all available threads across multiple cores, optimizing system resources for swift OCR execution. This built-in multithreading simplifies development and significantly boosts performance by integrating parallelism directly into the OCR workflow.

The library's multithreaded Tesseract implementation provides these key advantages:

  • Automatic CPU core utilization: IronOCR detects and uses all available cores without manual configuration
  • Thread-safe operations: All OCR operations are designed to be thread-safe by default
  • Optimized resource management: Memory and processing resources are efficiently allocated across threads
  • Scalable performance: Processing time decreases proportionally with the number of available cores

Here is a multithreaded read example in C#:

:path=/static-assets/ocr/content-code-examples/how-to/async-simple-multithreading.cs
using IronOcr;
using System;

var ocr = new IronTesseract();

using (var input = new OcrPdfInput(@"example.pdf"))
{
    var result = ocr.Read(input);
    Console.WriteLine(result.Text);
};
Imports IronOcr
Imports System

Private ocr = New IronTesseract()

Using input = New OcrPdfInput("example.pdf")
	Dim result = ocr.Read(input)
	Console.WriteLine(result.Text)
End Using
$vbLabelText   $csharpLabel

For advanced scenarios requiring fast OCR configuration, developers can fine-tune the multithreading behavior to match specific performance requirements while maintaining accuracy.

How Do I Use Async Support in IronOCR?

Asynchronous programming optimizes OCR performance by allowing developers to execute OCR tasks without blocking the main thread. This keeps applications responsive while processing large documents or images for text recognition. Async support enables the system to handle other tasks while OCR operations run in the background. This capability is crucial when implementing OCR progress tracking in user interfaces.

This section covers async support integration in IronOCR, demonstrating different methods to make OCR services non-blocking. IronOCR's async capabilities ensure optimal performance for both desktop applications requiring responsiveness during OCR operations and web services handling multiple concurrent OCR requests.

When Should I Use OcrReadTask Objects?

OcrReadTask objects enhance control and flexibility in OCR processes with IronOCR. These objects encapsulate OCR operations, allowing efficient management of text recognition tasks. This section demonstrates using OcrReadTask objects in your IronOCR workflow and shows how they initiate and optimize OCR tasks. OcrReadTask objects help maximize IronOCR capabilities when orchestrating complex document processing or fine-tuning application responsiveness.

OcrReadTask objects work best when:

  • You need fine-grained control over task execution
  • Implementing abort token functionality for cancellable operations
  • Managing multiple concurrent OCR operations with different priorities
  • Integrating with custom task schedulers or workflow engines
:path=/static-assets/ocr/content-code-examples/how-to/async-ocrtask.cs
using IronOcr;

IronTesseract ocr = new IronTesseract();

OcrPdfInput largePdf = new OcrPdfInput("chapter1.pdf");

Func<OcrResult> reader = () =>
{
    return ocr.Read(largePdf);
};

OcrReadTask readTask = new OcrReadTask(reader.Invoke);
// Start the OCR task asynchronously
readTask.Start();

// Continue with other tasks while OCR is in progress
DoOtherTasks();

// Wait for the OCR task to complete and retrieve the result
OcrResult result = await Task.Run(() => readTask.Result);

Console.Write($"##### OCR RESULTS ###### \n {result.Text}");

largePdf.Dispose();
readTask.Dispose();

static void DoOtherTasks()
{
    // Simulate other tasks being performed while OCR is in progress
    Console.WriteLine("Performing other tasks...");
    Thread.Sleep(2000); // Simulating work for 2000 milliseconds
}
Imports Microsoft.VisualBasic
Imports IronOcr

Private ocr As New IronTesseract()

Private largePdf As New OcrPdfInput("chapter1.pdf")

Private reader As Func(Of OcrResult) = Function()
	Return ocr.Read(largePdf)
End Function

Private readTask As New OcrReadTask(AddressOf reader.Invoke)
' Start the OCR task asynchronously
readTask.Start()

' Continue with other tasks while OCR is in progress
DoOtherTasks()

' Wait for the OCR task to complete and retrieve the result
Dim result As OcrResult = Await Task.Run(Function() readTask.Result)

Console.Write($"##### OCR RESULTS ###### " & vbLf & " {result.Text}")

largePdf.Dispose()
readTask.Dispose()

'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
'static void DoOtherTasks()
'{
'	' Simulate other tasks being performed while OCR is in progress
'	Console.WriteLine("Performing other tasks...");
'	Thread.Sleep(2000); ' Simulating work for 2000 milliseconds
'}
$vbLabelText   $csharpLabel

How Do I Use the ReadAsync Method?

ReadAsync() provides a direct mechanism for initiating OCR operations asynchronously. Without complex threading or task management, developers can integrate asynchronous OCR into their applications. This method prevents the main thread from blocking during OCR tasks, ensuring applications remain responsive.

The ReadAsync method works well for:

  • Desktop applications that need to maintain UI responsiveness
  • Web applications handling multiple simultaneous OCR requests
  • Batch processing scenarios where progress tracking is essential
  • Integration with modern async/await patterns in .NET applications
:path=/static-assets/ocr/content-code-examples/how-to/async-read-async.cs
using IronOcr;
using System;
using System.Threading.Tasks;

IronTesseract ocr = new IronTesseract();

using (OcrPdfInput largePdf = new OcrPdfInput("PDFs/example.pdf"))
{
    var result = await ocr.ReadAsync(largePdf);
    DoOtherTasks();
    Console.Write($"##### OCR RESULTS ###### " +
                $"\n {result.Text}");
}

static void DoOtherTasks()
{
    // Simulate other tasks being performed while OCR is in progress
    Console.WriteLine("Performing other tasks...");
    System.Threading.Thread.Sleep(2000); // Simulating work for 2000 milliseconds
}
Imports Microsoft.VisualBasic
Imports IronOcr
Imports System
Imports System.Threading.Tasks

Private ocr As New IronTesseract()

Using largePdf As New OcrPdfInput("PDFs/example.pdf")
	Dim result = Await ocr.ReadAsync(largePdf)
	DoOtherTasks()
	Console.Write($"##### OCR RESULTS ###### " & $vbLf & " {result.Text}")
End Using

'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
'static void DoOtherTasks()
'{
'	' Simulate other tasks being performed while OCR is in progress
'	Console.WriteLine("Performing other tasks...");
'	System.Threading.Thread.Sleep(2000); ' Simulating work for 2000 milliseconds
'}
$vbLabelText   $csharpLabel

Why Should I Use Async and Multithreading with IronOCR?

Combining async support and multithreading in IronOCR provides numerous benefits for modern application development:

Performance Benefits:

  • Improved Throughput: Process multiple documents simultaneously without blocking
  • Better Resource Utilization: Maximize CPU usage across all available cores
  • Reduced Latency: Start processing immediately without waiting for previous operations to complete
  • Scalable Architecture: Handle increasing workloads without architectural changes

Development Benefits:

  • Simplified Code: No need to manage threads manually - IronOCR handles the complexity
  • Modern Patterns: Full support for async/await patterns in Tesseract 5 for .NET
  • Easy Integration: Works seamlessly with existing .NET async infrastructure
  • Maintainable Solutions: Clear, readable code that follows .NET best practices

Multithreading in IronOCR optimizes OCR tasks significantly. The built-in multithreading capabilities, combined with methods like ReadAsync(), simplify handling large volumes of text data. This combination ensures applications remain responsive and efficient, making IronOCR an effective tool for creating high-performance software with streamlined text recognition capabilities. To get started with the complete feature set, check our NuGet package installation guide.

Frequently Asked Questions

How can I perform OCR asynchronously in C# without blocking my main thread?

IronOCR provides the ReadAsync method that enables non-blocking OCR execution. You can simply use `var result = await new IronOcr.IronTesseract().ReadAsync("image.png");` to perform OCR asynchronously, keeping your application responsive while processing documents.

Does OCR automatically use multiple CPU cores for better performance?

Yes, IronOCR automatically leverages all available CPU cores through built-in multithreading. The IronTesseract implementation detects and utilizes all cores without requiring manual configuration, providing optimized resource management and scalable performance.

What are the main benefits of multithreading in OCR processing?

IronOCR's multithreaded implementation offers automatic CPU core utilization, thread-safe operations by default, optimized resource management for memory and processing, and scalable performance where processing time decreases proportionally with available cores.

Can I process multiple PDF documents simultaneously with async OCR?

Yes, IronOCR's ReadAsync method works particularly well when processing PDF documents or handling multiple image files simultaneously, allowing you to process multiple documents concurrently without blocking your application.

Do I need to write special code to enable multithreading for OCR?

No, IronOCR requires no specialized API or manual configuration for multithreading. The library seamlessly integrates parallelism directly into the OCR workflow, automatically managing threads across multiple cores for optimal performance.

What is the OcrReadTask Object and how does it help with asynchronous processing?

The OcrReadTask Object in IronOCR enables you to take advantage of asynchronous concurrency when processing documents. It allows you to manage OCR operations asynchronously while the library handles the underlying multithreading complexity.

Is IronOCR fully compatible with .NET 10?

.NET 10 is supported by IronOCR via its latest release version 2025.12. You can install the library using NuGet (Install-Package IronOcr) and run async methods like ReadAsync() under .NET 10 without special configuration.

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of ...
Read More
Ready to Get Started?
Nuget Downloads 5,246,844 | Version: 2025.12 just released