I've a strange behavior on my WPF window. To summarize, I have a WPF window that do an async stuff on loaded event
if (AppContext.OnlineMode)
Task.Run(() => SynchronizeMails());
This function (synchronizeMails), do a lot of stuff (async contacting webservice, insert in database, refresh GUI, ...), and on first launch, it take a little long time.
I have a button that allow user to disconnect, bound to a command that show so messageBox depending of the current state. For my case, synchronizeMails set a bool to true, to prevents multiple synchronization and to prevents exit during treatment. My command implementation look at this boolean, and show a messageBox if is currently synchronizing.
ExitCommand = new RelayCommand(p => Task.Run(() =>
{
RestartAsked = true;
if (Synchronizing)
{
OpeningView.ShowWarning("...");
}
});
We have, for style reason, recoded message boxes in our own implementation, so the call to messageBox ShowWarning is only a ShowDialog on the main GUI, with no async/await stuff.
The strange is comming here : when user click OK on this message box, my async method just stop doing it's job, execute the finaly bloc (whole method is in a try-finally block to disable my boolean if there's some errors), and of course, the job isn't finished.
I don't understand why the showDialog with return make my async method stopping...
Does anyone have an idea ?