Sunday, October 2, 2022
HomeGame Developmentunity - Cancel a process provided that it will get re-run

unity – Cancel a process provided that it will get re-run

I’ve a sluggish proc gen perform that runs when a person modifications 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 the moment 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 = new CancellationTokenSource();
    var token = _tokenSource.Token;
    myData = await Process.Run(() => SlowFunction(Enter);

    // do stuff with new knowledge

This does work nevertheless it 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 manner I can assure the earlier process is finished earlier than beginning the brand new one?



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments