crossing thread boundary
-
Can I send text from a BackgroundWorker::DoWork() to a listbox in the main thread ? I want to keep the listbox in the main thread up to date with what's going on in BackgroundWorker::DoWork(). The BackgroundWorker::ProgressChanged() hasn't the parameter I need ( String^ ) and if I send the text straight to the listbox, an exception is raised. If not, is there another way to do it ?
-
Can I send text from a BackgroundWorker::DoWork() to a listbox in the main thread ? I want to keep the listbox in the main thread up to date with what's going on in BackgroundWorker::DoWork(). The BackgroundWorker::ProgressChanged() hasn't the parameter I need ( String^ ) and if I send the text straight to the listbox, an exception is raised. If not, is there another way to do it ?
As a general rule you can only touch GUI objects from the thread that created them. Use BeginInvoke() method on the form to transfer the call to the GUI thread and update the listbox from there. Once in the GUI thread check for IsDisposed before updating the listbox as its possible for the form to be destroyed beteen you calling BeginInvoke and the actual function being called by the GUI thread
System.IO.Path.IsPathRooted() does not behave as I would expect