"Cross-thread operation not valid: Control 'ListBox1' accessed from a thread other than the thread it was created on."This is a follow-up question raised when a fix I suggested was applied. This is another cross-threading problem which is easy to solve. Yes, UI cannot be controlled by any calls to any methods or properties a non-UI threads. The thread invocation mechanism should be used.
The delegate use to control UI should be
invoked to be called on the UI thread. Use the method
Invoke
or
BeginInvoke
of
System.Threading.Dispatcher
(can work with both WPF and Forms) or
System.Windows.Forms.Control
(Forms only, does not matter what instance of control; it just has to participate in currently running
System.Windows.Forms.Application
).
For detailed explanation on how it works and usage samples, please see my past answers:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
—SA