I have a textbox defined with multiline. It is used for showing the log of a process. As it becomes long, the scrollbar will appear. If I only append text to the control, the cursor will remain at the top so I will not see the actual log process of the last lines being added. So, I did this when I add some text:
LogWebServer.SelectionStart = LogWebServer.Text.Length
LogWebServer.ScrollToCaret()
This put the cursor at the end of the textbox. It then scroll the content at the bottom. I can then see the recent text being added.
However, this is causing a bug which freezes the application from time to time. It is easily reproducable when I don't comment those lines. Is there a better way to put the visual content at the bottom to be visual which might not cause the freeze bug to happen?