开发者

.NET Update WPF Control on own dedicated UI thread

开发者 https://www.devze.com 2023-01-18 04:31 出处:网络
I have a real-time application which constantly updates a UI log (RichTextBox control) in the form of a ListView contro开发者_JAVA技巧l. The control is updated with current application data received v

I have a real-time application which constantly updates a UI log (RichTextBox control) in the form of a ListView contro开发者_JAVA技巧l. The control is updated with current application data received via events. My application was running very slow and i found it was due to the ListView log being updated, which blocks the UI thread. As you can imagine, the application appears highly unresponsive to the user.

I know it's possible to launch a WPF Window on it's own dedicated UI thread. I was wondering if it's possible to host a WPF Control on it's own UI thread so that the main UI thread updates the rest of the window without being blocked?

If this is not possible, please recommend alternatives to remedy this dilemma.

Thanks!


You haven't posted any code, but why don't you bind the ListView to an ObservableCollection? You update the collection and it raises an event to tell the UI that it's changed - it's this that will update the UI.

There's many tutorials on how to do this - one such can be found on Switch On The Code


RichTextBox is an expensive control to update regularly.

It is not possible to host a WPF control on it's own UI thread.

ObservableCollection will not work in my case, as i do not have direct access to the objects that i am binding - 3rd party objects.

My solution, which requires minimal changes, was to base the UI Log control on a ListView. ListView has been optimised for bulk and regular updates - thanks to VirtualisedStackPanel tag.

0

精彩评论

暂无评论...
验证码 换一张
取 消