diff --git a/Meta.Vlc.Wpf/ThreadSeparatedImage.cs b/Meta.Vlc.Wpf/ThreadSeparatedImage.cs index 52f42f8..4a31426 100644 --- a/Meta.Vlc.Wpf/ThreadSeparatedImage.cs +++ b/Meta.Vlc.Wpf/ThreadSeparatedImage.cs @@ -15,31 +15,34 @@ namespace Meta.Vlc.Wpf public sealed class ThreadSeparatedImage : ThreadSeparatedControlHost { private static Dispatcher _commonDispatcher; + private static object _staticLock = new object(); public static Dispatcher CommonDispatcher { get { - if (_commonDispatcher == null) + lock (_staticLock) { - Thread separateThread = new Thread(() => + if (_commonDispatcher == null) { - Dispatcher.Run(); - }) - { - IsBackground = true - }; - separateThread.SetApartmentState(ApartmentState.STA); - separateThread.Priority = ThreadPriority.Highest; - - separateThread.Start(); - - while (Dispatcher.FromThread(separateThread) == null) - { - Thread.Sleep(50); + Thread separateThread = new Thread(() => + { + Dispatcher.Run(); + }) + { + IsBackground = true + }; + separateThread.SetApartmentState(ApartmentState.STA); + separateThread.Priority = ThreadPriority.Highest; + + separateThread.Start(); + + while (Dispatcher.FromThread(separateThread) == null) + { + Thread.Sleep(50); + } + _commonDispatcher = Dispatcher.FromThread(separateThread); } - _commonDispatcher = Dispatcher.FromThread(separateThread); } - return _commonDispatcher; } }