[WPF] Instanciation WPF à partir Console
Bonsoir à tous,
Comme dit dans l'énoncé du topic, j'instancie à la demande de l'utilisateur,
une fenêtre WPF à partir d'une application console.
Tout fonctionne bien au début, la fenêtre s'affiche etc...
À un moment, on peut demander la fermeture de l'application depuis la console, celle-ci se ferme correctement, cependant lors de la réouverture j'ai l'exception suivante :
Citation:
Impossible de créer plusieurs instances System.Windows.Application dans le même AppDomain.
Voici mon code :
Code:
1 2 3
| private Messenger Window = null;
private System.Windows.Application App = null;
private delegate void Msg(); |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
try
{
if (this.Window == null)
{
Thread T = new Thread(new ThreadStart(delegate
{
try
{
this.App = new System.Windows.Application();
this.Window = new Messenger();
this.App.Run(Window);
this.Window.Show();
}
catch (Exception E)
{
// EXCEPTION LEVÉE ICI
}
}));
T.SetApartmentState(ApartmentState.STA);
T.Start();
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
public void Test()
{
if (this.Window != null)
{
this.App.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Msg(this.ShutdownMessage));
}
}
public void ShutdownMessage()
{
this.App.Shutdown();
this.App = null;
this.Window = null;
} |
Si vous avez une idée..
Merci d'avance,
NeoKript
Edit :
C'est this.App = new System.Windows.Application(); qui lève l'exception !