I have a TextBox in my application, that it is used for showing state of process. Something like this
for(...)
textbox.text = "new line \r\n" + textbox.text
Problem is, when it is filling, so no text is visible, just white background. When process is done, then the all added text is visible. Is any option, how do solve this (I need to have text visible during whole process).
Thanks much.
If it's winforms, add Application.DoEvents();
in the loop, so that your application can refresh the UI.
This is the easiest, but not optimum, way to do it.
EDIT: Someone has downvoted this question without explaining way. That would be fair. The question poster knew about backroundworker and wanted a simpler solution.
Anyway, this solution can be perfect depending on the nature of the loop. If it's a loop with lots of iterations with each taking a short time to execute, making a call to Application.DoEvents() will work perfectly. I know it from my own experience. As it's a loop, it's quite possible that this is the case. Or perhaps it's possible to add several DoEvents() inside the loop. It simply checks the windows message queue and attends pending work.
I don't see any requisite that the user have to keep working on other parts of the application.
If it's a loop with few iterations, and which takes a very long time to execute each, them, it's neccessary to do it using threading.
But, rememeber that a novice can make mistakes if he uses threads without knowing very well its implications (I refer to thread-safety). What if the app gets a deadlock? What about corrupting non thread-safe structures used from different threads? What if the user closes the main Window while the background thread hasn't still finished? Let's be serious, this tool can be a bomb in unexperienced hands.
Besides, if you want to use threading BackgroundWorker is not the only solution.