FILTERTIMEOUTOPTIONS

Summary

The FILTERTIMEOUTOPTIONS structure contains options for the global filter operation timeout.

Syntax

typedef struct FILTERTIMEOUTOPTIONS 
{ 
   L_UINT uStructSize; 
   L_UINT uTimeoutMilliseconds; 
} FILTERTIMEOUTOPTIONS, * pFILTERTIMEOUTOPTIONS; 

Members

uStructSize

Size of the structure. This must be set before passing this structure to any LEADTOOLS function.

uTimeoutMilliseconds

Timeout, in milliseconds, at which point to abort long-running operations. The default value of 0 means there is no timeout set on long-running operations.

Comments

LEADTOOLS load file functions contains FILEREADCALLBACK that can be used to monitor the progress of loading images using L_LoadFile or L_LoadSvg2. The FILEREADCALLBACK callback is very suitable for raster images since the filter (PNG or TIF, for instance) can parse the image file structure quickly and start to send one or more scanlines to the callback quickly. Therefore, FILEREADLCALLBACK will start to occur shortly after L_LoadFile/L_LoadSvg2 is called. The application can use FILEREADLCALLBACK to show a progress bar to allow the user to monitor and potentially abort the load operation.

For complex document file formats such as DOCX and XSLX, this is not possible. The file filter will require significantly more time to parse the file structure. And the first scanline generated and sent to FILEREADLCALLBACK may not occur until after a considerable amount of time has passed since L_LoadFile/L_LoadSvg2 was called. This amount of time depends on the source file itself, and for very complex document files such as a very large XLSX spreadsheet with thousands or millions of rows, the time can be in seconds or even minutes.

Moreover, the parsing of the file structure usually occurs during L_FileInfo (whether called directly by the user or internally by L_LoadFile/L_LoadSvg2), which does not invoke FILEREADLCALLBACK at all.

For these kinds of documents, using FILEREADLCALLBACK to allow the user to abort long load operations is not feasible: the callback will occur at the very end of the operation after all the necessary data has been parsed and a significant amount of time could have been elapsed since the original L_LoadFile/L_LoadSvg2 was called.

Instead, the application can use L_SetFilterHeartbeatCallback to monitor and abort these very long operations. This callback occurs at the very start of L_FileInfo and then periodically during this function and L_LoadFile/L_LoadSvg2 to allow the user to abort the current operation if desired.

The FILTERHEARTBEATCALLBACK will fire and the application can set the return value to ERROR_USER_ABORT to abort the current operation as follows:

In other words, aborting a filter operation does not throw an exception. Instead, the application should check the returned object as described above to detect when the user aborted.

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 and return images in a web method). This server may require that no operation running within the web method can take more than 2 seconds. When this occurs, the operation should be aborted, and the work can be delegated to a dedicated thread or process outside of the web service worker thread.

L_SetFilterHeartbeatCallback can be used to install a callback that tracks the time and aborts all the operations taking more than the allocated time. Or, L_SetFilterTimeout can be used to set a global timeout interval for all get information and load operations. This function uses L_SetFilterHeartbeatCallback internally to install a handler that can take care of aborting long-running operations automatically.

For an example on using a heartbeat handler, refer to L_SetFilterHeartbeatCallback.

Currently filter heartbeat and timeout is only supported by the following file formats:

Usage

See Also

Example

Call this method with a very large and complex XLSX document and a timeout in seconds value
Returns SUCESS on success and ERROR_USER_ABORT if aborted
For each page, the image is loaded and passed to the processImage callback

// Call this method with a very large and complex XLSX document and a timeout in seconds value 
// Returns SUCESS on success and ERROR_USER_ABORT if aborted 
// For each page, the image is loaded and passed to the processImage callback 
 
typedef L_INT(*PROCESS_IMAGE)(BITMAPHANDLE* bitmapHandle, L_INT pageNumber); 
 
L_INT FilterTimeoutOptionsExample(L_TCHAR* inputFileName, L_UINT timeoutSeconds, PROCESS_IMAGE processImage) 
{ 
   L_INT ret = SUCCESS; 
 
   // Set the timeout 
   FILTERTIMEOUTOPTIONS filterTimeoutOptions; 
   memset(&filterTimeoutOptions, 0, sizeof(filterTimeoutOptions)); 
   ret = L_GetFilterTimeout(&filterTimeoutOptions, sizeof(FILTERTIMEOUTOPTIONS)); 
   if(ret != SUCCESS) 
      return ret; 
 
   filterTimeoutOptions.uTimeoutMilliseconds = timeoutSeconds * 1000; 
   ret = L_SetFilterTimeout(&filterTimeoutOptions); 
   if(ret != SUCCESS) 
      return ret; 
 
   // First, get information on the file to get the number of pages 
   L_INT pageCount = 0; 
   FILEINFO fileInfo; 
   memset(&fileInfo, 0, sizeof(FILEINFO)); 
   ret = L_FileInfo(inputFileName, &fileInfo, sizeof(FILEINFO), FILEINFO_TOTALPAGES, NULL); 
 
   // If L_FileInfo took more than timeoutSeconds then it returns ERROR_USER_ABORT 
   if(ret == ERROR_USER_ABORT) 
   { 
      printf("Aborted\n"); 
      return ret; 
   } 
 
   // Check for other errors 
   if(ret != SUCCESS) 
      return ret; 
 
   pageCount = fileInfo.TotalPages; 
 
   // Now load all the pages 
   LOADFILEOPTION loadFileOption; 
   memset(&loadFileOption, 0, sizeof(LOADFILEOPTION)); 
   L_GetDefaultLoadFileOption(&loadFileOption, sizeof(LOADFILEOPTION)); 
 
   for(L_INT pageNumber = 1; pageNumber <= pageCount; pageNumber++) 
   { 
      loadFileOption.PageNumber = pageNumber; 
 
      BITMAPHANDLE bitmapHandle; 
      memset(&bitmapHandle, 0, sizeof(BITMAPHANDLE)); 
      ret = L_LoadBitmap(inputFileName, &bitmapHandle, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, &loadFileOption, NULL); 
 
      // If L_LoadBitmap took more than timeoutSeconds then it returns ERROR_USER_ABORT 
      if(ret == ERROR_USER_ABORT) 
      { 
         printf("Aborted\n"); 
         return ret; 
      } 
 
      // Check for other errors 
      if(ret != SUCCESS) 
         return ret; 
 
      // Did we abort? 
      // Process the image and then delete it 
      processImage(&bitmapHandle, pageNumber); 
 
      L_FreeBitmap(&bitmapHandle); 
   } 
 
   // We successfully loaded and processed all the pages from the file 
   return SUCCESS; 
} 

Help Version 22.0.2023.7.11
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.