none
Dataset Thread-Safety RRS feed

  • Question

  •  I have a vb .net multi-threaded application with several datasets that are read/written to from a couple threads.  MSDN documentation says that datasets can handle multiple readers and a single 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?  I even experience this problem when only one thread is writing to a dataset (never deleting anything just updating values) and another thread reads from the same dataset.

    Any help would be greatly appreciated.

    Friday, February 2, 2007 1:23 PM

Answers

  • Hi,

    Make sure and correct that NO more than ONE thread should operate on the dataset at the same time so its better you sync all of your operation which is for sensetive data operation and seems to be problamatic in multithreading environment.

    Without code, I will not be able to answer you exactly so try for above suggestion and inform me the result or your question if any,

    HTH,

    Saturday, February 3, 2007 8:19 PM

All replies

  • What is the value of i when the error occurs? are you using a For loop?

    For i As Integer = 0 To CMPDAT.Tables(0).Rows.Count -1 Step 1
       
    CMPDAT.Tables(0).Rows(i).Item("ID")
    Next
    Friday, February 2, 2007 3:10 PM
  • Usually the value of the index in error is zero.  Some are for loops, some are do whiles. 

     

    Friday, February 2, 2007 3:28 PM
  • Hi,

    Make sure and correct that NO more than ONE thread should operate on the dataset at the same time so its better you sync all of your operation which is for sensetive data operation and seems to be problamatic in multithreading environment.

    Without code, I will not be able to answer you exactly so try for above suggestion and inform me the result or your question if any,

    HTH,

    Saturday, February 3, 2007 8:19 PM