1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
//méthode appellée par le client de la librairie
public static void ShowError(string contextMessage, System.Exception ex, string contextId)
{
System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, showErrorDispatched, contextMessage, ex, contextId);
}
// méthode utilisée pour dispatcher l'appel dans le bon thread...
private static void ShowErrorDispatched(string contextMessage, System.Exception ex, string contextId)
{
ErrorInfo errorInfo = new ErrorInfo(contextMessage, ex, contextId);
ErrorDialog.Show(errorInfo);
}
// méthode qui crée puis affiche la boite
public show(ErrorInfo errorInfo)
{
ErrorDialog errorDialog = new ErrorDialog(errorInfo);
// windows.Count = errorDialog + toutes les autres fenêtre, donc si c'est 1
// ou moins, c'est qu'il n'y a que errorDialog, donc pas de MainWindow
if (Application.Current.Windows.Count > 1)
{
// lien avec la windows principale du moment
errorDialog.Owner = Application.Current.MainWindow;
errorDialog.ShowDialog();
}
else
{
// affiche une boite de dialog sans parent... MARCHE PAS
errorDialog.ShowDialog();
}
} |
Partager