You have a BackgroundWorker
, so you have everything you need. The progress event is called on the UI thread, so if the worker reports progress in the standard way (by calling ReportProgress(int32, object), and passing the string to be appended as the second parameter, the form's progress handler can call AppendText
. The background thread will never outrun the UI that way.
I suspect you're calling BeginInvoke
to update your UI. Another way to solve the problem would be to call Invoke
.
You can do much better if you have your background worker save up, say, 10 lines, and then pass them all to the progress event at once. That'll reduce the overhead of updates and cause your background thread to process faster.