Unplanned
Last Updated: 13 Jun 2025 10:08 by ADMIN
Piet
Created on: 11 Jun 2025 13:11
Category: Telerik Document Processing
Type: Feature Request
0
DocumentProcessing: Introduce a CancellationToken mechanism for import and export of documents

In the 2025 version of the Documents packages, "TimeSpan? timeout" were added to a number of interfaces, with the old versions obsoleted, for example: IWorkbookFormatProvider.Import & IWorkbookFormatProvider.Export.

This is a very strange choice, because this limits the flexibility of the interfaces for no reason at all. By only providing the TimeSpan parameter and not a CancellationToken is currently impossible to cancel the operation because e.g. an API request was canceled.

Internally these methods are implemented by first creating a cancellation token using

using CancellationTokenSource cancellationTokenSource = CancelationTokenSourceFactory.CreateTokenSource(timeout);

the token from this CancellationTokenSource is then passed to a protected method. Because this internal method uses a CancellationToken anyway, there is practically 0 development cost to exposing this in the interface, which makes the choice not to do so even more confusing.

The interfaces should expose methods that take a CancellationToken instead of a TimeSpan. This would allow for the same functionality as the TimeSpan parameter, by simply passing a cancellation token with a CancelAfter set with a TimeSpan, and an extension method could be provided for the interface which does exactly that, so users can still call these methods with a TimeSpan parameter if they wish to do so for convenience.

Please, in the next version, make these interfaces methods like this:

Workbook Import(Stream input, CancellationToken cancellationToken = default);
void Export(Workbook workbook, Stream output, CancellationToken cancellationToken = default);

and, for convenience, add extension methods for these like this:

public static class WorkbookFormatProviderExtensions
{
    public static Workbook Import(this IWorkbookFormatProvider workbookFormatProvider, Stream input, TimeSpan? timeout)
    {
        using CancellationTokenSource cancellationTokenSource = CancelationTokenSourceFactory.CreateTokenSource(timeout);
        return workbookFormatProvider.Import(input, cancellationTokenSource.Token);
    }
}

Affected interfaces I've run into so far:

  • Telerik.Windows.Documents.Spreadsheet.FormatProviders.IWorkbookFormatProvider
  • Telerik.Windows.Documents.Common.FormatProviders.IFormatProvider<T>

There may be more with this same pattern, I haven't checked.

2 comments
ADMIN
Yoan
Posted on: 13 Jun 2025 10:08

Hello Piet,

Thank you very much for taking the time to write back and share your detailed feedback — it is greatly appreciated.

The current design of these APIs was intentionally created to work with a TimeSpan rather than a CancellationToken, primarily to help mitigate potential abuse scenarios such as DDOS attacks by ensuring that all operations have a clear and enforced timeout boundary.

That said, your input is absolutely valid and provides a very helpful perspective on how the APIs could be made more flexible for broader use cases, especially in scenarios where external cancellation needs to be integrated. This would indeed be a great addition to complement the existing functionality.

For that reason, I allowed myself to update this current thread and make it an official feature request on your behalf - DocumentProcessing: Introduce a CancellationToken mechanism for import and export of documents. It should consider implementing additional overloads that also accept a CancellationToken parameter. This way, we can offer both the protective timeout mechanism and the flexibility you’ve suggested.

If you are interested in this task, please know that you can cast your vote for it in order to increase its priority in our backlog and to subscribe so you get notified about potential status updates in the future.

Thank you once again for your valuable input — it truly helps us improve the product.

Regards,
Yoan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Piet
Posted on: 11 Jun 2025 14:03

it would be better for the extension methods to not have a nullable TimeSpan parameter:

public static class WorkbookFormatProviderExtensions
{
    public static Workbook Import(this IWorkbookFormatProvider workbookFormatProvider, Stream input, TimeSpan timeout)
    {
        using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(timeout);
        return workbookFormatProvider.Import(input, cancellationTokenSource.Token);
    }
}