Reputation: 935
I have a class, that is responsible for the logic of a classic snake game logic, that uses System.Timers.Timer
. Because the exact same class is used for a Windows Forms version of the exact same project, I don't want to change that.
How can I connect a WPF window's method to an event that was designed to be used for WinForms (ISynchronizeInvoke
)? I'm searching quite a while to achieve this without rewrite my logic class.
Upvotes: 0
Views: 1116
Reputation: 43606
You can use the Dispatcher
to invoke to the UI thread
private void ThreadingTimerTick(object state)// or whatever your method is.
{
Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate()
{
// do stuff
});
}
Upvotes: 2