Currently I'm aware of the following Dispatcher
objects.
If you have a text view, you can use
IWpfTextView.VisualElement.Dispatcher
.If your class is constructed by MEF (marked with
[Export]
and not directly constructed from your own code), then you can use the fact that the MEF part resolution algorithm and construction occurs on the UI thread, allowing the use ofDispatcher.CurrentDispatcher
. For example:[Export(typeof(ISomeInterface))] public class MyClass : ISomeInterface { private readonly Dispatcher _dispatcher; public MyClass() { _dispatcher = Dispatcher.CurrentDispatcher. } }
You can use
Application.Current.Dispatcher
from any code.
What, if any, is the recommended practice for obtaining a Dispatcher
?