Mahdi Ghiasi
Mahdi Ghiasi

Reputation: 15301

Create new thread, how much time is needed?

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

Answers (4)

oleksii
oleksii

Reputation: 35905

Take a look at Parallel.For and Parallel.ForEach

Upvotes: 1

L.B
L.B

Reputation: 116138

See these extension methods

System.Threading.Tasks.Parallel.For
System.Threading.Tasks.Parallel.ForEach
System.Threading.Tasks.Parallel.Invoke

Upvotes: 3

Jesse C. Slicer
Jesse C. Slicer

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

SLaks
SLaks

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

Related Questions