[ad_1]
I’ve a gradual proc gen perform that runs when a person adjustments any parameters.
If a parameter is modified earlier than it has accomplished, I would like 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 process.
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 process to be run earlier than the cleanup code and cancelation within the earlier one have accomplished.
Is there a method I can assure the earlier process is completed earlier than beginning the brand new one?
[ad_2]