I created an addin in C# and WPF (MVVM). I need to update the GUI after I ran several queries that are taking 8 seconds via repository.SQLQuery(...).
To not block the main thread of the Enterprise Architect, I created a task where to run these queries and at the end I need to update the GUI. The problem is that is not working Application.Current.Dispacher because EA doesn't provide a UI thread dispatcher mechanism.
How can I create a method to no block the main Thread and at the end to update the GUI?
private ICommand _runAsyncButton;
public ICommand RunAsyncButton
=> _runAsyncButton ??
(_runAsyncButton =
new DelegateCommand(async p => await ExecuteSomethingAsync()));
private async Task ExecuteSomethingAsync()
{
await Task.Run(() => {
// taking 8 seconds
repository.SQLQuery(...)
repository.SQLQuery(...)
repository.SQLQuery(...)
if (Application.Current.Dispatcher != null)
Application.Current.Dispatcher.Invoke(() =>
{
// code to update the GUI is throwing an exception because Application.Current is null
});
});
}