I currently have a program that runs several “intense” queries. I added a textbox and presented status updates when a query was starting, eding and how many were left. This would suite my need, but the textbox doesn’t actually display anything until all the queries are finished. It then displays all the updates at once. I’m assuming updating the textbox in another thread would solve this issue, and that is where I am lost. How can I use a thread that receives a message from the main form running the query and have it display it in the textbox?
Share
The
BackgroundWorkercomponent suits your need (sample code is there in the MSDN link). You handle itsDoWorkevent and perform the actual query in it. You report the progress by calling itsReportProgressmethod. To display the reported progress, you should handle itsProgressChangedevent and update the UI. You start the job by calling theRunWorkerAsyncmethod of the background worker. UsingBackgroundWorkerrelieves you from manually starting and stopping threads and communicating with the UI thread to update the progress bar.