ImageViewer control started complaining about being called from another thread.

Dear community, I am experiencing crashes when trying to launch the VideoPlayer and ImageViewerControl controls from inside a dispatcher.

Recently something in my app has started calling the controls from another thread rather than the main UI thread (still trying to figure out why)

We started using Dispatchers and Invokes but it still crashes, here is a sample piece of code where the issue happens:

Dispatcher dispatcherUI = Dispatcher.CurrentDispatcher;

    dispatcherUI.BeginInvoke(new Action(() =>

    {

      streamingPanel.Controls.Clear();

      VP.MediaElement.Source = new Uri(path);

      streamingPanel.Controls.Add(EH);

      VideoIsPlaying = true;

      VideoRandom = isRandom;

      VP.MediaElement.Play();

      this.BringToFront();

      this.TopMost = true;

      Log.SaveLog("Mostrando video: " + path);

    }));

Does anyone know why this happens and how we can solve this?

Many thanks,

Adrián

We’re in doubt if you find the UI thread or it could be another thread. This might help - https://stackoverflow.com/questions/2663070/how-do-i-get-the-ui-threads-dispatcher

If this does not lead you to a solution, please provide a stack trace.