Adam L. S.
Adam L. S.

Reputation: 935

System.Timers.Timer invoke WPF component's method

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

Answers (1)

sa_ddam213
sa_ddam213

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

Related Questions