MBarley

I have a multi-threaded application with several datasets that are read/written to from a couple threads. I have read that datasets can handle multiple readers and one writer. I have synclocks around all dataset writes and no synchronization around reads. I am experiencing random "Index was outside the bounds of the array." exceptions where a dataset item is in a conditional statement, for example:

If CInt(CMPDAT.Tables(0).Rows(i).Item("ID")) = 0 Then

Do I need to synchronize read operations as well

Any help would be greatly appreciated.



Re: Visual Basic General DataSet Thread-Safety?

hayder MArzouk

Hi,

I Think use more thant thread to read/write collections (here collections are tables, rows and columns) is not a nice idea.

Imagine u are reading items of a collection containing 10 items. Then a cross thread will remove an item from the collection. So when the first thread will try to obtain the last index (9) of the collection (wich was deleted) you will have the "Index out of range" exception.

So you must also lock reading operation.

I have experienced such problems and finally i decided to not use multithreading with collections.

Anyway....

HTH





Re: Visual Basic General DataSet Thread-Safety?

MBarley

Thanks for the reply. I am still a little confused, for example I have a dataset that is only written to by one thread and read by another thread, after running the program for a while I will see the random index outside the bounds of the array exceptions. There is never anything deleted from the dataset, just values being updated by one thread and read by another thread.