This is a .NET 9 WPF project and as far as I know when awaiting Tasks ConfigureAwait(false) extension should be used here.
The Voltage property binds to a sliders Value.
FireAndForgetSafeAsync also uses ConfigureAwait(false) internally.
public float Voltage
{
get => _voltage;
set
{
if (SetProperty(ref _voltage, value))
{
VoltageErrorState.ResetError();
DebounceAndExecuteVoltageCommand(value).FireAndForgetSafeAsync(HandleError);
}
}
}
private async Task DebounceAndExecuteVoltageCommand(float newValue)
{
bool debounced = await _voltageDebounce.DebounceAsync(250).ConfigureAwait(false);
if (!debounced)
return;
await _voltageCommand.ExecuteAsync(newValue);
}
public class Debouncer
{
private CancellationTokenSource? _cancellationTokenSource;
public async Task<bool> DebounceAsync(int delayMilliseconds)
{
try
{
_cancellationTokenSource?.Cancel();
_cancellationTokenSource = new CancellationTokenSource();
await Task.Delay(delayMilliseconds, _cancellationTokenSource.Token);
}
catch (TaskCanceledException)
{
return false;
}
return true;
}
}
However when running the application in Debug mode slow downs are noticeable if the slider is moved constantly (the command is not triggered because of the debouncer). If I remove the ConfigureAwait(false) call inside the Debouncer class, the slider can be moved much smoother. The slow downs are only noticeable in Debug mode not in Release mode.
Am I using ConfigureAwait wrong here?
Is it sufficient to just use ConfigureAwait(false) in the setter?
2