Getting the correct WPF Manager in a thread

In the object constructor, I need to create a WPE mediaElement object:

m_videoMedia = new MediaElement();

but the class can also be created from another thread, so I need to use

Dispatcher.Invoke(DispatcherPriority.Normal,
    (Action)(() => { m_videoMedia = new MediaElement(); })); 

But how can I get the correct dispatcher instance in this constructor: s

+5
source share
4 answers

Most likely you can just use Dispatcher.CurrentDispatcher .Invoke ...

However, if for some reason this does not work, you can force your class to get a dispatcher reference as part of its constructor. Just go in Dispatcher.CurrentDispatcherfrom the user interface stream at build time.

+8
source

:

: Application.Current.Dispatcher

Application.Current null, .

, Application.

+5

WPF DispatcherObject, Dispatcher, . , . , , , MediaElement.

+2

If you add links to System.Windows.Formsyour project, you can continue to use Application.DoEvents()in WPF.

-1
source

All Articles