Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Loooping through DataSet with threads but locking

Loooping through DataSet with threads but locking

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Danpeking
    wrote on last edited by
    #1

    Hi, I need to have maybe 5 threads running which all use the same DataSet and need to loop through all the rows retrieved but each row must be processed by one thread only (e.g. I don't want row 1 to be processed by thread 1 and thread 3). I can also use a DataReader if that helps, but I need to dow some locking logic I would have thought. Can anybody please help as I've no experience of doing this before? Thank you

    OriginalGriffO 1 Reply Last reply
    0
    • D Danpeking

      Hi, I need to have maybe 5 threads running which all use the same DataSet and need to loop through all the rows retrieved but each row must be processed by one thread only (e.g. I don't want row 1 to be processed by thread 1 and thread 3). I can also use a DataReader if that helps, but I need to dow some locking logic I would have thought. Can anybody please help as I've no experience of doing this before? Thank you

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Pass each thread a row to process, or a list of rows to process. Lock won't help you much here since it suspends the thread until the lock is released. You would need to check if a thread is (or has) processed that row, which is a different logic altogether.

      If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      D 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Pass each thread a row to process, or a list of rows to process. Lock won't help you much here since it suspends the thread until the lock is released. You would need to check if a thread is (or has) processed that row, which is a different logic altogether.

        If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

        D Offline
        D Offline
        Danpeking
        wrote on last edited by
        #3

        Ok, thanks. So how do check if it has processed or is processing a row which has been used/is being used? Thanks

        OriginalGriffO 1 Reply Last reply
        0
        • D Danpeking

          Ok, thanks. So how do check if it has processed or is processing a row which has been used/is being used? Thanks

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Yo will have to do that yourself - either by handing the thread only the row(s) you want it to process (my preferred option) or by keeping a list of all rows that have been processed and checking it in your thread. If you go for the second option, you will need to lock the list before your threads access it!

          If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          D 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Yo will have to do that yourself - either by handing the thread only the row(s) you want it to process (my preferred option) or by keeping a list of all rows that have been processed and checking it in your thread. If you go for the second option, you will need to lock the list before your threads access it!

            If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

            D Offline
            D Offline
            Danpeking
            wrote on last edited by
            #5

            Thanks, yes it would probably be best to just set each numbered thread to use certain segments of the data. For example, I have set the first thread to process rows 0 to 9999 of the DataSet, etc. Thanks

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups