I am new to multi-threading and I stumbled across an error which I was hoping someone could explain to me why was happening.
My initial program code did not have multi-threading and I was populating some charts with data from a datagridview. I was getting values like this:
Val = dgv.Rows(counter).Cells(columnName).Value
Since I was populating four charts using the same grid, I wanted to put this chart population process on multiple threads. I got an error when trying to update GUI elements (such as labels and a progress bar) and stumbled across this thread: .NET Controls: Why aren't all calls thread-safe?
So my fix was to have the main thread update the GUI elements, and the backgroundworkers just report progress to the main thread.
However, I still getting a cross-thread error when trying to read the value using the function above. I'd like to know why this is the case.
I solved my problem using Invoke (which I believe is the correct way of doing it), ie. something like this:
dgv.Invoke(New ReadDGVCallBack(AddressOf ReadDGV), counter, "Name")
where "Name" is the column name.
However, I still am curious to know why I can't read a value from a datagridview from another thread. Since I am not modifying it, shouldn't it be fine if data is just being read? Could someone shed some light on this?
Thanks for all the help