1: public partial class SplashWindow : Window
2: {
3: public SplashWindow()
4: {
5: InitializeComponent();
6: }
7:
8: // Instance statique de la fenêtre
9: public static SplashWindow _monSplashScreen;
10:
11: /// <summary>
12: /// Affiche le SplashScreen
13: /// </summary>
14: public static void ShowMe()
15: {
16: Thread thread = new Thread(() =>
17: {
18: // Instancie la fenêtre
19: _monSplashScreen = new SplashWindow();
20: // Place la fenêtre par dessus les autres
21: _monSplashScreen.Topmost = true;
22: // Affiche la fenêtre
23: _monSplashScreen.Show();
24:
25: // Démarre une nouvelle "pompe de messages" associée au thread
26: System.Windows.Threading.Dispatcher.Run();
27:
28: // Lorsqu'InvokeShutdown() sera appelée,
29: // on rend le focus à la fenêtre principale de l'application
30: App.Current.Dispatcher.Invoke(
31: new Action(() => App.Current.MainWindow.Activate()));
32: });
33:
34: // Place le thread appelant en STA (cloisonnement des threads)
35: thread.SetApartmentState(ApartmentState.STA);
36:
37: // Démarre le nouveau thread
38: thread.Start();
39: }
40:
41: public static void CloseMe()
42: {
43: // Teste l'existence d'une instance de la fenêtre
44: if (_monSplashScreen != null)
45: {
46: // Demande à la fenêtre de se fermer
47: // depuis le Dispatcher qui lui est associé
48: _monSplashScreen.Dispatcher.Invoke(
49: new Action(() => _monSplashScreen.Close()));
50:
51: // Demande l'arrêt du dispatcher associé à la fenêtre
52: _monSplashScreen.Dispatcher.InvokeShutdown();
53: }
54: }
55: }