During the execution of the code in a parallel thread, 200 lines of text are generated (approximately 20 characters in each line), after which an event is triggered there, in which these lines are assigned to the TextBox
via the Dispatcher
. But alas, the program freezes for about 500 ms. Is there a way to display three-dimensional text in this TextBox
without UI
hanging?
|
2 answers
Slow work with large amounts of text is a long-standing TextBox control problem in WPF. If it is not solved by unloading the control in time, then several options remain:
- use another graphic component, for example AvalonEdit
- working with text as with a list is a good example here.
You can still try FlowDocumentPageViewer , but I have not tried it.
- The variant with AvalonEdit just came up to me, but the question is, is it possible to change the color for hyperlinks in it? Or have to describe your style? - BwehaaFox
|
make the text update method asynchronous. In this case, the text will be displayed when the method is executed, and the UI does not hang. Send the function code - I can show how to make it asynchronous, if that.
- The text is generated and so asynchronously, the delay is exactly at the moment of assignment:
textbox.Text += str;
, and putting it into a separate thread is not an option since an exception is raised where it says that theUI
in a different thread. - BwehaaFox - Asynchronous methods can reach fields without exception - Vladimir Paliukhovich
- 2@VladimirPaliukhovich man brakes directly on the assignment of the text. This assignment always occurs in the UI stream. So, the brakes, most likely, should be looked for in another - layout, text volume, etc. - andreycha
|
UI
hangs. That is, if inTextBox
there are a couple of thousand lines of such, then even adding and deleting a character through the interface will hang the window. What control? - BwehaaFox