相关疑难解决方法(0)

为什么我的多线程比单线程慢?

我知道有几个人问了一个与此相似的问题,但我找不到任何能让我理解为什么它变慢的回答.

因此,我为自己对Visual Studio 2013中的线程对象的理解制作了一个小程序控制台程序.我的CPU是Intel Core i7,供应可以使用多个线程.

我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class Program
    {

        static TimeSpan MTTime;
        static TimeSpan STTime;

        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();


            Console.WriteLine(Environment.NewLine + "---------------Multi Process-------------" + Environment.NewLine);

            Thread th1 = new Thread(new ParameterizedThreadStart(Process));
            Thread th2 = new Thread(new ParameterizedThreadStart(Process));
            Thread th3 = new Thread(new ParameterizedThreadStart(Process));
            Thread th4 = new Thread(new ParameterizedThreadStart(Process));

            th1.Start("A");
            th2.Start("B");
            th3.Start("C");
            th4.Start("D");

            th1.Join();
            th2.Join(); …
Run Code Online (Sandbox Code Playgroud)

c# multithreading

32
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×1

multithreading ×1