Timeout in milliseconds, after which time loading is aborted.
public int TimeoutMilliseconds {get; set;}
Public Property TimeoutMilliseconds() As Integer
Get
Set
public:
property Int32 TimeoutMilliseconds
{
Int32 get()
void set(Int32 value)
}
Timeout in milliseconds, after which time loading is aborted. The default value is 0.
The default value is 0, meaning there is no timeout set. The DocumentFactory will try to load slow documents regardless of long it takes.
Complex document file formats such as DOCX and XSLX can require significantly more time to parse the file structure than simpler file formats. The amount of time depends on the source file itself, and very complex document files such as a large XLSX spreadsheet with thousands or millions of rows, can take seconds or even minutes. DocumentFactory.LoadFromFile or DocumentFactory.LoadFromUri will not return until all the file data is parsed.
For such documents, using the TimeoutMilliseconds allows the user to abort long load operations if required. After the allocated timeout has passed, DocumentFactory will abort the load operation and null instead of a valid LEADDocument is returned from LoadFromFile or LoadFromUri.
In other words, aborting a load operation does not throw an exception. Instead, the application should check the returned LEADDocument: if it is null, the user aborted.
Note that TimeoutMilliseconds is an approximate value and only measures the time it took the RasterCodecs object to extract information about the document such as its format, number of pages, and the size of each page with the initial GetInformation call. Times for other operations such as downloading the image data from an external URL are not included in TimeoutMilliseconds.
Internally, the value of TimeoutMilliseconds is set into the RasterCodecs.Options.Timeout.TimeoutMilliseconds property of the RasterCodecs object used to load this document. Therefore, not all types of documents can have their load operation aborted by this property. Refer to CodecsTimeoutOptions for more information.
Some applications may have a requirement to abort all load operations that take more than a certain time, for instance a web server that uses LEADTOOLS to load documents in a web method. This server may require that all operations running within the web method to not take more than 2 seconds. When this occurs, the operation should be aborted, and the work can delegate to a dedicated thread or process outside of the web service worker thread.
The time it takes to load a document is recorded and stored in LEADDocument.LoadDuration.
This example will set a set a timeout of 2 seconds and then tries to load a complex document. The sample may or may not work depending on the document and machine speed.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Document.Writer;
using Leadtools.Document;
using Leadtools.Caching;
using Leadtools.Annotations.Engine;
using Leadtools.Ocr;
using Leadtools.Barcode;
using Leadtools.Document.Converter;
public string TryLoadDocument(Uri documentUri)
{
// This method returns the document ID in the cache if the document was loaded
// successfully, or null if the document took more than 2 seconds to load.
string documentId;
// The cache we are using
var cache = new FileCache();
cache.PolicySerializationMode = CacheSerializationMode.Json;
cache.DataSerializationMode = CacheSerializationMode.Json;
cache.CacheDirectory = @"c:\cache-dir";
// Try to load the document and save into the cache
var loadDocumentOptions = new LoadDocumentOptions();
loadDocumentOptions.Cache = cache;
// Set the timeout to 2 seconds
loadDocumentOptions.TimeoutMilliseconds = 2 * 1000;
LEADDocument document = DocumentFactory.LoadFromUri(documentUri, loadDocumentOptions);
if (document != null)
{
Console.WriteLine($"Success, it took {document.LoadDuration} ms to load this document");
// We managed to load it, save it into the cache and return the document ID
document.AutoSaveToCache = false;
document.AutoDeleteFromCache = false;
document.SaveToCache();
documentId = document.DocumentId;
document.Dispose();
}
else
{
// LoadFromUri did not throw an exception, therefore, documentUri
// is a valid image/document format that LEADTOOLS understands but the
// operation timed out
Console.WriteLine("Timed-out");
documentId = null;
}
return documentId;
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Document.Writer
Imports Leadtools.Svg
Imports Leadtools.Document
Imports Leadtools.Caching
Imports Leadtools.Annotations.Engine
Imports Leadtools.Barcode
Imports Leadtools.Ocr
Imports LeadtoolsDocumentExamples.LeadtoolsExamples.Common
Imports Leadtools.Document.Converter
Public Shared Function TryLoadDocument(documentUri As Uri) As String
' This method returns the document ID in the cache if the document was loaded
' successfully, or null if the document took more than 2 seconds to load.
Dim documentId As String
' The cache we are using
Dim cache As New FileCache()
cache.PolicySerializationMode = CacheSerializationMode.Json
cache.DataSerializationMode = CacheSerializationMode.Json
cache.CacheDirectory = "c:\cache-dir"
' Try to load the document and save into the cache
Dim loadDocumentOptions As New LoadDocumentOptions()
loadDocumentOptions.Cache = cache
' Set the timeout to 2 seconds
loadDocumentOptions.TimeoutMilliseconds = 2 * 1000
Dim document As LEADDocument = DocumentFactory.LoadFromUri(documentUri, loadDocumentOptions)
If Not IsNothing(document) Then
Console.WriteLine($"Success, it took {document.LoadDuration} ms to load this document")
' We managed to load it, save it into the cache and return the document ID
document.AutoSaveToCache = False
document.AutoDeleteFromCache = False
document.SaveToCache()
documentId = document.DocumentId
document.Dispose()
Else
' LoadFromUri did not throw an exception, therefore, documentUri
' is a valid image/document format that LEADTOOLS understands but the
' operation timed out
Console.WriteLine("Timed-out")
documentId = Nothing
End If
Return documentId
End Function
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document