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?

  • add text asynchronously and in chunks, at which the reaction time of the UI will suit you. I would also advise to try using a different graphic control. - Ice2burn
  • @ Ice2burn, tried to add text breaking it. The problem happens not so much even in the appendix, as it turned out. The more text is added to the control, the longer it takes to display and the longer the UI hangs. That is, if in TextBox 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
  • Do you add text B using AppendText ()? Set the UndoLimit property to a smaller one. - Ice2burn
  • Show the code, huh? Strange that textbox is one and lines 200. - VladD

2 answers 2

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:

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 the UI 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