Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf method to start the application message loop

I need to create a Form in a different thread and keep it ranning until a user performe some action in the main thread (click a button).

It is not very difficult to do using

System.Windows.Forms.Application.Run(new ApplicationContext());

that starts an application message loop in the current thread. But this solution requires the usage of System.Windows.Forms namespace, which in not a wpf namespace.

Do you know a wpf-way of achieving this goal? =)

P.S. without starting an application message loop the thread will be imidiatly terminated after processing of the last expression in it. So, the Form will appear only for a moment and will be closed. =(

like image 491
user101375 Avatar asked Feb 09 '10 08:02

user101375


1 Answers

Use System.Windows.Threading.Dispatcher.Run()

like image 75
Nir Avatar answered Sep 22 '22 04:09

Nir