TimeoutMilliseconds Property (original) (raw)
Summary
Timeout in milliseconds, after which time loading is aborted.
Syntax
public int TimeoutMilliseconds {get; set;}
public:
property Int32 TimeoutMilliseconds
{
Int32 get()
void set(Int32 value)
}
Property Value
Timeout in milliseconds, after which time loading is aborted. The default value is 0.
Example
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;
}