I’ve a gradual proc gen operate that runs when a consumer adjustments any parameters.
If a parameter is modified earlier than it has accomplished, I need it to cancel the duty and begin a brand new one.
At present I’ve it checking if a cancellation token is null, and if not requesting a cancellation earlier than launching a brand new activity.
public static async void Generate(myInputParams Enter)
{
SectorData sectorData;
if (_tokenSource != null)
{
_tokenSource.Cancel();
_tokenSource.Dispose();
}
_tokenSource = new CancellationTokenSource();
var token = _tokenSource.Token;
myData = await Process.Run(() => SlowFunction(Enter);
// do stuff with new information
}
This does work but it surely appears to me that it is potential for the brand new activity to be run earlier than the cleanup code and cancelation within the earlier one have accomplished.
Is there a manner I can assure the earlier activity is finished earlier than beginning the brand new one?