←Select platform

CodecsFilterHeartbeatEventArgs Class

Summary

Data for the RasterCodecs.FilterHeartbeat event.

Syntax
C#
C++/CLI
Python
public class CodecsFilterHeartbeatEventArgs : EventArgs 
public: 
   ref class CodecsFilterHeartbeatEventArgs : EventArgs 
class CodecsFilterHeartbeatEventArgs(EventArgs): 
Remarks

Refer to RasterCodecs.FilterHeartbeat for more information.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
// Call this method with a very large and complex XLSX document and a timeout in seconds value 
// Returns true on success and false if aborted 
// For each page, the image is loaded and passed to the processImage action 
public bool FilterHeartbeatExample(string inputFileName, int timeoutSeconds, Action<RasterImage, int> processImage) 
{ 
   using (var rasterCodecs = new RasterCodecs()) 
   { 
      // This is the start time, we will reset this value 
      // anytime we start an operation 
      DateTime startOperationTime = DateTime.Now; 
 
      // Create a heartbeat handler 
      EventHandler<CodecsFilterHeartbeatEventArgs> heartbeatHandler = (sender, e) => 
      { 
         // Abort if it has been more than timeoutSeconds since last operation 
         TimeSpan timeSpan = DateTime.Now - startOperationTime; 
         if (timeSpan.TotalSeconds > timeoutSeconds) 
         { 
            e.Abort = true; 
         } 
      }; 
 
      // Install the heartbeat handler 
      rasterCodecs.FilterHeartbeat += heartbeatHandler; 
 
      // First, get information on the file to get the number of pages 
      RasterImageFormat format; 
      int pageCount = 0; 
 
      // Reset the start time 
      startOperationTime = DateTime.Now; 
      using (CodecsImageInfo imageInfo = rasterCodecs.GetInformation(inputFileName, true)) 
      { 
         // If GetInformationt took more than timeoutSeconds then we aborted the operation 
         // inside heartbeatHandler and GetInformation will return RasterImageFormat.Unknown 
         format = imageInfo.Format; 
         if (format != RasterImageFormat.Unknown) 
            pageCount = imageInfo.TotalPages; 
      } 
 
      // Did we abort? 
      if (format == RasterImageFormat.Unknown) 
      { 
         // Yes, fail 
         rasterCodecs.FilterHeartbeat -= heartbeatHandler; 
         return false; 
      } 
 
      // Now load all the pages 
 
      for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++) 
      { 
         // Reset the start time 
         startOperationTime = DateTime.Now; 
         RasterImage image = rasterCodecs.Load(inputFileName, pageNumber); 
         // If Load took more than timeoutSeconds then we aborted the operation 
         // inside heartbeatHandler and Load will return null 
 
         // Did we abort? 
         if (image == null) 
         { 
            // Yes, fail 
            rasterCodecs.FilterHeartbeat -= heartbeatHandler; 
            return false; 
         } 
 
         // Process the image and then delete it 
         processImage(image, pageNumber); 
         image.Dispose(); 
      } 
 
      rasterCodecs.FilterHeartbeat -= heartbeatHandler; 
 
      // We successfully loaded and processed all the pages from the file 
      return true; 
   } 
} 
 
import java.io.*; 
import java.net.*; 
import java.nio.file.Paths; 
import java.util.*; 
import java.time.Instant; 
import java.time.Duration; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.codecs.RasterCodecs.FeedCallbackThunk; 
import leadtools.drawing.internal.*; 
import leadtools.imageprocessing.*; 
import leadtools.imageprocessing.color.ChangeIntensityCommand; 
import leadtools.svg.*; 
 
 
Instant start; 
int timeoutSeconds; 
 
public void filterHeartbeatExample() throws InterruptedException { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String inputFileName = combine(LEAD_VARS_IMAGES_DIR, "large_sheet_5k.xlsx"); 
   RasterCodecs rasterCodecs = new RasterCodecs(); 
 
   Calendar.getInstance(); 
   start = Instant.now(); 
   timeoutSeconds = 20; 
 
   // Create a heartbeat handler 
   // Install the heartbeat handler 
   rasterCodecs.addFilterHeartbeatListener(heartbeatHandler); 
 
   // First, get information on the file to get the number of pages 
   RasterImageFormat format; 
   int pageCount = 0; 
 
   Calendar.getInstance(); 
   CodecsImageInfo imageInfo = rasterCodecs.getInformation(inputFileName, true); 
 
   // If GetInformation took more than timeoutSeconds then we aborted the 
   // operation 
   // inside heartbeatHandler and GetInformation will return 
   // RasterImageFormat.Unknown 
   format = imageInfo.getFormat(); 
   if (format != RasterImageFormat.UNKNOWN) { 
      pageCount = imageInfo.getTotalPages(); 
   } 
 
   // Did we abort? 
   if (format == RasterImageFormat.UNKNOWN) { 
      // Yes, fail 
      rasterCodecs.addFilterHeartbeatListener(heartbeatHandler); 
      return; 
   } 
 
   // Now load all the pages 
   for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++) { 
      // Reset the start time 
      start = Instant.now(); 
      RasterImage image = rasterCodecs.load(inputFileName, pageNumber); 
      // If Load took more than timeoutSeconds then we aborted the operation 
      // inside heartbeatHandler and Load will return null 
 
      // Did we abort? 
      if (image == null) { 
         // Yes, fail 
         rasterCodecs.addFilterHeartbeatListener(heartbeatHandler); 
         return; 
      } 
 
      // Process the image and then delete it 
      processImage(image, pageNumber); 
      image.dispose(); 
   } 
 
   rasterCodecs.addFilterHeartbeatListener(heartbeatHandler); 
 
   // We successfully loaded and processed all the pages from the file 
   return; 
} 
 
CodecsFilterHeartbeatListener heartbeatHandler = new CodecsFilterHeartbeatListener() { 
 
   public void onHeartbeat(CodecsFilterHeartbeatEvent e) { 
      // Abort if it has been more than timeoutSeconds since last operation 
      Instant end = Instant.now(); 
      Duration timeElapsed = Duration.between(start, end); 
      if (timeElapsed.getSeconds() > timeoutSeconds) { 
         e.setAbort(true); 
      } 
   } 
 
}; 
Requirements

Target Platforms

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

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