0
votes

In my method "sendconfig_dowork(object sender, DoWorkEventArgs e)" I like to show to user also the window when is finished.

When method is "not external" i defined so and working fine:

var window = System.Windows.Application.Current.Windows.OfType<MetroWindow>().FirstOrDefault();
                if (window != null)
                    await window.ShowMessageAsync(@"Operation successed", @"Operation successed");

But this is not working in "External" Method like Background worker. I'm having trouble figuring out how I supposed to define that will work insider background worker? Or how is the best way to define that?

Program is written in C# WPF and MVVM politic. Thanks! If any question please ask.

1

1 Answers

0
votes

You have to call ShowMessageAsync in the UI thread. E.g. you can use the application's dispatcher, if you target .NET Framework 4.5:

var window = System.Windows.Application.Current.Windows.OfType<MetroWindow>().FirstOrDefault();
if (window != null) {
    Application.Current.Dispatcher.InvokeAsync(() => window.ShowMessageAsync(@"Operation successed", @"Operation successed");
}