I have a function that gets a Func as a parameter and executes it inside of a task in a async method in order to display indeterminate progress bar while the function is working....
private async void Invoke(Func<string> function)
{
if(calculation?.Status == TaskStatus.Running) await calculation;
calculation = Task.Run(function);
InvokeA(() => prg.Height = double.NaN);
InvokeA(() => prg.Visibility = Visibility.Visible);
Result = await calculation;
InvokeA(() => prg.Visibility = Visibility.Hidden);
InvokeA(() => prg.Height = 0);
}
The problem is when ever the function reaches the:
Result = await Calculation;
it sort of stops... it never gets to actually setting the value or closing the progress bar.
Invoke Is Called from a Textbox.KeyDown Method if the key is Enter:
if (SpecialCommands.DoesExist(Text))
{
Invoke(() => SpecialCommands.Invoke(Parameter));
if (!string.IsNullOrEmpty(Result)) Text += $" ---> {Result}";
}
variables definition:
calculation = Task<string>
Result = string
prg = ProgressBar
Parameter = string that isn't connected to the UI