[]
        
(Showing Draft Content)

CancellationToken

Class CancellationToken

java.lang.Object
com.grapecity.documents.excel.CancellationToken

public class CancellationToken extends Object
A token that propagates notification that operations should be canceled.

This class is thread-safe. Typically, a CancellationToken is obtained from a CancellationTokenSource via CancellationTokenSource.getToken() and passed to long-running operations such as Workbook.processTemplate(CancellationToken). The operation can then check isCancellationRequested() to determine whether cancellation has been requested.


 try (CancellationTokenSource cts = new CancellationTokenSource()) {
     CancellationToken token = cts.getToken();
     cts.cancelAfter(Duration.ofSeconds(10));
     workbook.processTemplate(token);
 } catch (Exception e) {
 }
 
  • Constructor Details

    • CancellationToken

      public CancellationToken()
  • Method Details

    • isCancellationRequested

      public boolean isCancellationRequested()
      Gets whether cancellation has been requested for this token.
      
       try (CancellationTokenSource cts = new CancellationTokenSource()) {
           CancellationToken token = cts.getToken();
           cts.cancel();
           boolean cancellationRequested = token.isCancellationRequested();
       }
       
      Returns:
      Cancellation status.