Cancel loading or paginating file on demand or after timeout

Hi GemBox Team,

I have a general question regarding the loading process of files into DocumentModel (or in the other components as MailMessage / PresentationDocument / ExcelFile) and paginating them: both operations can take a long time, is there a way to cancel those operations after a specific time or when a Cancellation Token is cancelled?

Kind regards,
Sarah

Hi Sarah,

Yes, please take a look at the “Progress Reporting and Cancellation” example for GemBox.Document:
https://www.gemboxsoftware.com/document/examples/progress-reporting-and-cancellation/108

The same feature is also available in GemBox.Spreadsheet as well:
https://www.gemboxsoftware.com/spreadsheet/examples/progress-reporting-and-cancellation/121

Unfortunately, this feature is currently not available in GemBox.Presentation and GemBox.Email.

Anyway, I hope this helps, let me know if you need anything else.

Regards,
Mario

Hi Mario,

this helps! Thank you, I will have a closer look on it.

Regards,
Sarah

Hi Mario,

unfortunately the cancellation via ProgressChanged event in the loading process of DOCX and XLSX files does not cover some of my use cases, like loading other file formats or getting the paginator.
As I am trying to transform my application from .net-Framework (where I could abort the loading or paginating threads) to .net Core (where aborting threads is no longer supported), the lack of cancellation options becomes critical.
Is there another option, to force file loading or paginating to stop?

Best regards,
Sarah

We have now added support for canceling the pagination in both GemBox.Spreadsheet and GemBox.Document, please try again with these NuGet packages:

Install-Package GemBox.Spreadsheet -Version 49.0.1556-hotfix
Install-Package GemBox.Document -Version 35.0.1595-hotfix

So now you have a cancellation option when saving to PDF (PdfSaveOptions.ProgressChanged), when saving to image format (ImageSaveOptions.ProgressChanged), and when paginating content (PaginatorOptions.ProgressChanged).

Regarding the rest of the file formats (besides the mentioned XLSX and DOCX), unfortunately, they currently lack support for this event.

Last, have you tried some alternatives to Thread.Abort, for example, using the Thread.Interrupt or the recently introduced ControlledExecution.
For more information, see the following post:

Hi Mario,

thank you for adding the ProgressChangedEvent in the PaginatorOptions.
Sadly I need an equivalent support or a possibility to work with CancellationTokens for all file formats to safely remove my fallback handling with Thread.Abort.
Do you perhaps have an indication if or when a similar mechanism might be available?

The Thread.Interrupt function does not interrupt my loading and paginating thread, because it is still in a running state while calling the load method and not in the required state of “WaitSleepJoin”.
ControlledExecution is marked as deprecated and only available in .net 7 and above and I am still using .net6 and netStandard2.0 in most parts of the application.

Best regards,
Sarah

Hi Sarah,

Unfortunately, the ProgressChanged event for other formats won’t be available any time soon.

The only other suggestion that I have is to run the code in a separate process and then when needed you can use Process.Kill.

Or upgrade to .NET 7. Note that the ControlledExecution is deprecated from the beginning, when it was introduced. This was done on purpose to discourage its usage because it has the same issues that Thread.Abort had.