/// <summary> /// The dispatcher service used to call to the UI thread and analyze performance /// </summary> private void PlayVideoExpernally(ContentControl host) { this.mediaPlayerProxyFactory = new MediaPlayerProxyFactory(); var workerThread = new Thread( () => { var isHostUnInitialized = true; // need to access these properties from UI thread Application.Current.Dispatcher.Invoke( () => { isHostUnInitialized = host.Content == null; }); if (isHostUnInitialized) { var videoUrl = string.Format(@"C:\Video\4KVideo0{0}.mp4", this.count++); Trace.WriteLine(videoUrl); var mediaUri = new Uri(videoUrl); Application.Current.Dispatcher.Invoke( () => { host.ToolTip = videoUrl; host.ParentOfType<Border>().ToolTip = videoUrl; var textBlock = host.ParentOfType<Border>().FindName("VideoUrlTextBlock") as TextBlock; if (textBlock != null) { textBlock.Text = videoUrl; } }); this.Player = this.mediaPlayerProxyFactory.GetPlayerInstance(mediaUri, this.externalProcessId); this.externalProcessId = 0; if (this.Player != null) { this.Player.Initialize(mediaUri.AbsoluteUri); this.Media = this.Player.SetupPlayerObject(); } if (this.Media != null) { Application.Current.Dispatcher.Invoke( () => { if (host != null) { host.Content = this.Media; } }); } if (this.Player != null) { this.Player.StreamingStatusChanged += this.PlayerStreamingStatusChanged; this.Player.PlayerError += this.Player_PlayerError; this.Player.Play(); } } }); workerThread.Start(); }