mortenstarck
mortenstarck

Reputation: 2803

Thread difficulties in WPF

Im trying to play an song then a person is calling my application. But then the mediaElement1.play(); is used i just get an The calling thread cannot access this object because a different thread owns it.. I have tried to use threading. But then the problem just moves. Best regard Morten Starck

Upvotes: 0

Views: 53

Answers (1)

paul
paul

Reputation: 22011

Does this do the trick?

        if (!mediaElement1.CheckAccess())
            mediaElement1.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                (Action)delegate
                {
                    mediaElement1.play();
                });

Upvotes: 2

Related Questions