I work on an engine programmed in C# that creates and executes .NET 4.5 Tasks. Within these tasks code is being executed from different APIs. One of them being the Tabular Object Model (TOM).
I want to be able to cancel a running Task and my problem is that the function of TOM i call within the task, has no possibility to receive a CancelationToken.
Code here:
Task t = Task.Run( () =>
{
// may check cancelation token status before
TomApi.CallSomeMethod(); // cannot abort this very call
// may check cancelation token status after
});
So my problem is, when some user wants to cancel that running Task t
i have no possibility to call cancel on it.
For methods that support async
I do it like this:
Task t = Task.Run( () =>
{
TomApi.CallSomeMethodAsync(token);
});
I know also that I can check the CancelationToken
status in the code, but my point is that a call within the task is already running and I could only check for that status before or after that function call