I noticed by accident that reading text from UI controls doesn't throw a "Cross thread operation not valid" error like it does if you try to change the text without using Invoke or ReportProgress inside a BackgroundWorker1_DoWork sub.
For example this code throws an error:
While this does not:Code:Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Textbox1.text = "Changed text" End Sub
Should I continue to program inside DoWork like this since it doesn't throw an error or is there some negative to this? Should I just pass the variables through e.Argument or use Invoke instead? Is there any hidden drawbacks to either way or is it the same?Code:Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Dim checked as boolean = Checkbox1.Checked Dim newString as String = Textbox1.text End Sub
Thanks.




Reply With Quote
