.net multithreaded application

I have a multi-core processor, but the .net application I wrote uses only one of the cores. how can I get it to use more than one core when this option is available.

+3
source share
4 answers

This does not happen for free. Using multiple cores requires multiple threads. You will need to explicitly add thread support to your program in order to use multiple cores at the same time.

Here's a great article exploring how you can use multiple managed-code kernels using parallel library tasks (also known as parallel wireframe extensions ).

http://msdn.microsoft.com/en-us/magazine/cc163340.aspx

+7

Microsoft Parallel Extensions to.NET Framework 3.5, JaredPar, .

, "for-loop" , System.Threading.Parallel Parallel Extension. , 0 maxnum:

System.Threading.Parallel.For(0, maxNum + 1, x => IsPrime(x));  

, ?

, System.Parallel. , SO peers , .

alt text

+4

@JaredPar . , , . .

​​ , , , ..

, , .

0

.

multitrheading - ThreadPool.

ThreadPool MSDN:

using System;
using System.Threading;
public class Example {
    public static void Main() {

        // Queue the task.
        ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));

        Thread.Sleep(1000);

        Console.WriteLine("Main thread exits.");
    }

    // This thread procedure performs the task. 
    static void ThreadProc(Object stateInfo) {

        // No state object was passed to QueueUserWorkItem, so  
        // stateInfo is null.
        Console.WriteLine("Hello from the thread pool.");
    }
}
0

Source: https://habr.com/ru/post/1705908/


All Articles