Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii,
is it possible to loop 2 items or 5 items at a tym instead of one
by one ....

i know this not an obvious question but stell i want an answer from professionals ...


thxxxsss.....
Posted
Comments
Kenneth Haugland 23-May-15 6:53am    
ParaLLel.For(0,Array.Length, Sub(i)
....
End Sub)
Member 10521418 23-May-15 23:19pm    
thxxxxsssss

1 solution

Um. Yes...and no.
If you have spare cores, then you can use separate threads to genuinely do a number of things at the same time - but how many is not guaranteed, and will vary from moment to moment depending on the load on the system as a whole. And doing things truly independently requires pretty much that the tasks are not interdependent. If item 2 requires data from item 1's calculations, then it gets pretty complex to work out.

And if this will improve performance depends on the task you need to perform: adding threading adds an overhead of it's own, so a lot of small operations in different threads can be slower and require more resources than the same operations done sequentially in the same thread.

But...start by looking at Parallel.ForEach[^] and the BackgroundWorker[^] class - they are the easiest way to get started with this.

But be careful - there are a lot of "hidden" complexities when you start multithreading.
 
Share this answer
 
Comments
Member 10521418 23-May-15 8:14am    
m using multithreading already but by using that ofcouse making task faster but lot of disturbances...
exp:-
by using two sub the time arises to 5 sec but by one sub it is within 2 sec ... so multithreading is good but have some limitations.....
OriginalGriff 23-May-15 8:16am    
Yes, because there is an overhead to the setup and management of a thread.
Member 10521418 23-May-15 23:19pm    
http://www.codeproject.com/Questions/994330/cpu-usage-while-processing-or-performing-any-task

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900