Search code examples
c#positionmediaelement

I need a way to access media element properties from another thread


I have a MediaElement built into a GUI using visual studios, but in the backend code I need to access the Position property in the video it loads in order to use the time in some calculations. I'm getting an error saying I can't access it because another thread owns it.

I've tried using the GetProperty() GetValue() methods, and I've also approached it with an invoker but can't find a method in MediaElement to get the position.

Is there an easy way to access properties of an object in another thread?


Solution

  • you didn't post the error but I'm guessing it's telling you that you can't just access objects on the UI thread from other/non-UI threads, in WPF you typically need the Dispatcher to invoke into another thread. more info and samples here.