Rosmarine Popcorn
Rosmarine Popcorn

Reputation: 10967

What can I do to make my C# application take advantage of multiple processor cores?

I've been doing some tests about the way a .NET C# application uses resources, like CPU or memory. I wrote some loops that calculate values for a large amount of numbers and I'm satisfied with the weight of the algorithm.

I have a Quad Core 2.4 GHz processor, but I've noticed that In Task Manager, my application is only using 25% of my CPU. Why isn't it using 100%? Does that mean that a .NET C# Application compiled in VS 2008 only supports Single Core CPU? Or is there a way that I can force it to use all CPUs?

Upvotes: 6

Views: 5818

Answers (4)

Matt Ellen
Matt Ellen

Reputation: 11592

It all depends on how you can modify your code to use more than one core.

Unless you are doing parallel or multi threaded operations, then the programme won't use more than one core.

.NET 4 has a library that can help you: Parallel LINQ. For more information see this page: http://msdn.microsoft.com/en-us/library/dd997425.aspx

Upvotes: 5

Rosmarine Popcorn
Rosmarine Popcorn

Reputation: 10967

What about if i use Background-workers ,if i have CPU QuadCore 4CPU's can somebody write an example how could it react @ that CPU ?

Upvotes: 1

Xaqron
Xaqron

Reputation: 30837

Use .NET 4.0 TaskLibrary which is designed for benefiting from multi-core processors.

Upvotes: 2

Henk Holterman
Henk Holterman

Reputation: 273179

It will run at 1 core unless you specifically start some threading.

The easiest way is to push a method onto the ThreadPool.

   System.Threading.ThreadPool.QueueUserWorkItem(DoSomething);

   void DoSomething() { ... }

Upvotes: 2

Related Questions