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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Need help for perform some operation parallely

Need help for perform some operation parallely

Scheduled Pinned Locked Moved C#
helpperformance
9 Posts 4 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.
  • S Offline
    S Offline
    superselector
    wrote on last edited by
    #1

    I have one requirement , I have a gridview where i will load details of some ip address with its credential. Currently i will perform task related to ip adresses one by one. but now we have a requirement to speed up the process. Now i want to do the task parallely. I can use multithreading and start the threads and join them but the issue is i want to process only 2 set of ip i.e threads at one given point of time.So once these two threads complete the next set of two ips from gridview should be processed parallely.is it possible using multithreading .

    R G 2 Replies Last reply
    0
    • S superselector

      I have one requirement , I have a gridview where i will load details of some ip address with its credential. Currently i will perform task related to ip adresses one by one. but now we have a requirement to speed up the process. Now i want to do the task parallely. I can use multithreading and start the threads and join them but the issue is i want to process only 2 set of ip i.e threads at one given point of time.So once these two threads complete the next set of two ips from gridview should be processed parallely.is it possible using multithreading .

      R Offline
      R Offline
      Ron Beyer
      wrote on last edited by
      #2

      Yes, here's how I would do it: When the user tells the program to start, add all the IP's to a Queue[^]. Then create two background workers[^]. Give each background worker one of the IP's and remove them from the queue. When the background worker completes, save the data and give it another IP from the queue (remove it when done). Keep doing this for each background worker until the queue is empty.

      S 1 Reply Last reply
      0
      • R Ron Beyer

        Yes, here's how I would do it: When the user tells the program to start, add all the IP's to a Queue[^]. Then create two background workers[^]. Give each background worker one of the IP's and remove them from the queue. When the background worker completes, save the data and give it another IP from the queue (remove it when done). Keep doing this for each background worker until the queue is empty.

        S Offline
        S Offline
        superselector
        wrote on last edited by
        #3

        can we do it using Thread class

        OriginalGriffO 1 Reply Last reply
        0
        • S superselector

          I have one requirement , I have a gridview where i will load details of some ip address with its credential. Currently i will perform task related to ip adresses one by one. but now we have a requirement to speed up the process. Now i want to do the task parallely. I can use multithreading and start the threads and join them but the issue is i want to process only 2 set of ip i.e threads at one given point of time.So once these two threads complete the next set of two ips from gridview should be processed parallely.is it possible using multithreading .

          G Offline
          G Offline
          GuyThiebaut
          wrote on last edited by
          #4

          In short the answer is no - multi threading is not the same as parallel processing. One thing to bear in mind is if you do decide to dive into parallel processing what is your strategy for conflicts when two processes need to update the same data at the same time? Probably the simplest and cheapest method is to up the RAM, on the computer running this application, and index any tables that are used in any background databases.

          “That which can be asserted without evidence, can be dismissed without evidence.”

          ― Christopher Hitchens

          R 1 Reply Last reply
          0
          • S superselector

            can we do it using Thread class

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

            Yes. BackgroundWorker is just a wrapper for the Thread class, with progress reporting added in. It's easier to use, but it creates Thread instances for you, is all.

            Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

            "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

            1 Reply Last reply
            0
            • G GuyThiebaut

              In short the answer is no - multi threading is not the same as parallel processing. One thing to bear in mind is if you do decide to dive into parallel processing what is your strategy for conflicts when two processes need to update the same data at the same time? Probably the simplest and cheapest method is to up the RAM, on the computer running this application, and index any tables that are used in any background databases.

              “That which can be asserted without evidence, can be dismissed without evidence.”

              ― Christopher Hitchens

              R Offline
              R Offline
              Ron Beyer
              wrote on last edited by
              #6

              On a single core machine I would agree with you, but those are not common these days. Threading done correctly is parallel programming and there are very easy ways to deal with resource contention. Many .NET BCL collections are atomic (thread safe), he could just store the results in there while running multiple threads and update the UI based on one way bindings. Even the .NET TPL runs on a single machine, maybe you are thinking of distributed processing? He doesn't say that this is a RAM intensive or database application, its a network one that takes some time to gather information about network resources so I'm a little confused about your comment on RAM or database operations...

              G 2 Replies Last reply
              0
              • R Ron Beyer

                On a single core machine I would agree with you, but those are not common these days. Threading done correctly is parallel programming and there are very easy ways to deal with resource contention. Many .NET BCL collections are atomic (thread safe), he could just store the results in there while running multiple threads and update the UI based on one way bindings. Even the .NET TPL runs on a single machine, maybe you are thinking of distributed processing? He doesn't say that this is a RAM intensive or database application, its a network one that takes some time to gather information about network resources so I'm a little confused about your comment on RAM or database operations...

                G Offline
                G Offline
                GuyThiebaut
                wrote on last edited by
                #7

                I read that he is using a datagrid and this led me to believe that may be using a database to populate the datagrid. He doesn't state what the source of the datagrid is, only the contents. He then mentions that he need to run two processes in parallel I understood that he wants to literally run two processes at the same time(that's what parallel means to me) - based on my understanding of threading this is not guaranteed by threading processes. Hence my suggestion for more RAM to which could speed up bottlenecks in processing time and indexes based on my assumption with regards to the datagrid.

                “That which can be asserted without evidence, can be dismissed without evidence.”

                ― Christopher Hitchens

                1 Reply Last reply
                0
                • R Ron Beyer

                  On a single core machine I would agree with you, but those are not common these days. Threading done correctly is parallel programming and there are very easy ways to deal with resource contention. Many .NET BCL collections are atomic (thread safe), he could just store the results in there while running multiple threads and update the UI based on one way bindings. Even the .NET TPL runs on a single machine, maybe you are thinking of distributed processing? He doesn't say that this is a RAM intensive or database application, its a network one that takes some time to gather information about network resources so I'm a little confused about your comment on RAM or database operations...

                  G Offline
                  G Offline
                  GuyThiebaut
                  wrote on last edited by
                  #8

                  Ooh, I just refreshed myself on looked at this .NET TPL[^] I stand corrected regarding threading...

                  “That which can be asserted without evidence, can be dismissed without evidence.”

                  ― Christopher Hitchens

                  R 1 Reply Last reply
                  0
                  • G GuyThiebaut

                    Ooh, I just refreshed myself on looked at this .NET TPL[^] I stand corrected regarding threading...

                    “That which can be asserted without evidence, can be dismissed without evidence.”

                    ― Christopher Hitchens

                    R Offline
                    R Offline
                    Ron Beyer
                    wrote on last edited by
                    #9

                    If the operation he were conducting were processor/memory intensive I would agree that threading may not solve his issue, but with network operations most of the time is spent with the socket in a wait state (sending or receiving), which frees up more threads to get into the wait state or do other work. Since data may arrive from a thread started later than an earlier one, threading and tasks really do behave as if they operate in parallel, even on a single core processor. The TPL was a major change to the .NET framework, which is why .NET 4 is an entire new runtime than 3/3.5 which runs on/are extensions to the 2.0 runtime.

                    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