Reputation:
I am trying to create an animation that moves some images across the canvas in my applications layout.
The canvas is named layout
which belongs to the main window and the timer is calling the event Animation.Clouds(layout, 1)
. When attempting this I am getting an error regarding the object is owned by another thread. This has left me to believe that the cause is the timer not being able to pass the context of layout
, causing the error.
How would I solve this issue and pass layout
to the timer in order for the animation to work?
Upvotes: 1
Views: 142
Reputation: 35477
The problem is that you can ONLY update a UI element, when you are on the UI thread. The Timer event gets invoke on a different thread.
In Windows.Forms you can use BeginInvoke
. I'm sure WPF has something similar.
Upvotes: 0
Reputation: 50722
use DispatcherTimer instead, it fire a tick in dispatcher thread it is created
Upvotes: 1