private CancellationTokenSource _tokenSource;
public async Task RunBigTask()
{
_tokenSource = new CancellationTokenSource();
// Some logic here...
await OtherClass.RunSmallerTasks(_tokenSource.Token);
// Some other logic here...
}
// In another class...
public async Task RunSmallerTasks(CancellationToken ct)
{
for(int i = 0; i < k; i++)
{
ct.ThrowIfCancellationRequested();
try
{
await RunSmallTask();
}
catch(Exception e)
{
// Sending telemetry here about the exception.
}
}
}
private CancellationTokenSource _tokenSource;
public async Task RunBigTask()
{
_tokenSource = new CancellationTokenSource();
// Some logic here...
await OtherClass.RunSmallerTasks(_tokenSource.Token);
// Some other logic here...
}
// In another class...
public async Task RunSmallerTasks(CancellationToken ct)
{
for(int i = 0; i < k; i++)
{
ct.ThrowIfCancellationRequested();
try
{
await RunSmallTask();
}
catch(Exception e)
{
// Sending telemetry here about the exception.
}
}
}