Need help for perform some operation parallely
-
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 .
-
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 .
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.
-
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.
can we do it using Thread class
-
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 .
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
-
can we do it using Thread class
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 – ∞)
-
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
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...
-
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...
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
-
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...
-
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.