简体   繁体   English

一次更新多个窗口

[英]Updating multiple windows at once

In my WPF application, I receive UDP data at 100 ms interval. 在我的WPF应用程序中,我每隔100毫秒接收一次UDP数据。 I have to display the data in multiple windows. 我必须在多个窗口中显示数据。 The UDP server runs on a separate thread and calls the main UI thread through Dispatcher.Invoke for UI updates. UDP服务器在单独的线程上运行,并通过Dispatcher.Invoke调用主UI线程以进行UI更新。 Since there is only one main UI thread, the updates to the different windows is not parallel ie, first UI in one window is updated, then another window. 由于只有一个主UI线程,因此对不同窗口的更新不是并行的,即,先更新一个窗口中的UI,然后再更新另一个窗口。

Is there a way to divide the UI thread so that all the windows are updated simultaneously? 有没有一种方法可以划分UI线程,以便同时更新所有窗口?

You can create and run your windows in new UI threads 您可以在新的UI线程中创建和运行窗口

var thread = new Thread(new ThreadStart( () =>
{        
    var window= new Window();
    window.Show();

    System.Windows.Threading.Dispatcher.Run();
}));

thread.SetApartmentState(ApartmentState.STA);   
thread.IsBackground = true;   
thread.Start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM