Reputation: 15301
I have a main loop, and there are some loops inside it.
I want to multithread the loops inside. (a complete cycle of main loop takes 50-200 milliseconds. the main loop has about 3-4 loops inside)
How much time is needed to create a new Thread
?
What is the fastest way to create and destroy threads?
Upvotes: 2
Views: 2366
Reputation: 116138
See these extension methods
System.Threading.Tasks.Parallel.For
System.Threading.Tasks.Parallel.ForEach
System.Threading.Tasks.Parallel.Invoke
Upvotes: 3
Reputation: 20157
If you have .NET 4 (VS 2010) at your disposal, look at the Task Parallel Library - specifically Parallel.For()
and Parallel.ForEach()
for threading your looping constructs.
Upvotes: 2
Reputation: 887449
You should use the ThreadPool
.
This allows you to reuse threads from a managed pool instead of creating and destroying new threads each time.
Upvotes: 4