Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个类,负责经典蛇游戏逻辑的逻辑,它使用System.Timers.Timer. 因为完全相同的类用于完全相同的项目的 Windows 窗体版本,所以我不想更改它。
System.Timers.Timer
如何将 WPF 窗口的方法连接到设计用于 WinForms ( ISynchronizeInvoke) 的事件?我正在寻找相当长的时间来实现这一目标,而无需重写我的逻辑类。
ISynchronizeInvoke
您可以使用Dispatcher调用 UI 线程
Dispatcher
private void ThreadingTimerTick(object state)// or whatever your method is. { Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate() { // do stuff }); }