parallel.invoke

    #region  parallel.invoke 
    /* 
      资料参考
      https://www.cnblogs.com/Leo_wl/p/6218247.html  
     
      parallel.invoke()方法 提供了任务并行性模式(也就是多个任务并行运行), 
     
stopWatch.Start();   //开始计时

stopWatch.Stop();   //停止计时

stopWatch.Reset();  //重置StopWatch

stopWatch.Restart(); //重新启动被停止的StopWatch

stopWatch.ElapsedMilliseconds //获取stopWatch从开始到现在的时间差,单位是毫秒

    */

    //public class RarallelDemo
    //{
    //    private Stopwatch stopwatch = new Stopwatch();

    //    public void Run1()
    //    {
    //        Thread.Sleep(2000);
    //        Console.WriteLine("Task 1 is cost 2 sec");
    //    }

    //    public void Rum2()
    //    {
    //        Thread.Sleep(3000);
    //        Console.WriteLine("Task 2 is cost 3 sec");
    //    }
    //    public static void Main()
    //    {
    //        RarallelDemo n = new RarallelDemo();
    //        n.ParallelInvokeMethod();
    //    }

    //    public void ParallelInvokeMethod()
    //    {
    //        stopwatch.Start();
    //        Parallel.Invoke(Run1, Rum2);//invoke 并行执行
    //        stopwatch.Stop();
    //        Console.WriteLine("Parallel run " + stopwatch.ElapsedMilliseconds + " ms.");//并行,花费的时间是执行时间最长的的那个线程,
    //        stopwatch.Restart();//重置时间
    //        Run1();
    //        Rum2();//串行执行
    //        stopwatch.Stop(); 
    //        Console.WriteLine("Normal run " + stopwatch.ElapsedMilliseconds + " ms.");//因为是串行,所以花费的时间应该是各线程执行时间的和
    //    }
    //}
    试一下
    ///
    //public class t
    //{
    //    public const int a = 1000;

    //    public static void Main()
    //    {
    //      // ThreadStart threadStart = Tt;
    //        ThreadStart threadStart1 = Dowork;
          
    //       // Thread thread = new Thread(threadStart);
    //        Thread thread1 = new Thread(threadStart1);
    //        //thread.Start();
    //        //for (int count = 0; count < a; count++)
    //        //{
    //        //    Console.WriteLine(count);
    //        //}
    //        //thread.Join();
    //    }
    //    public static void Dowork()
    //    {
    //        for (int count = 0; count < a; count++)
    //        {
    //            Console.WriteLine(count);
    //        }
//    }

        //public static void  Tt()
        //{
        //    for (int i = 0; i < 100001; i++)
        //    {
               
        //        int a = i / 1000 % 10 ;
        //        int b = i / 100 %10 ;
        //        int c = i / 10 %10;
        //        int d = i / 1 %10;
               
        //        if (a*a*a + b*b*b + c*c*c+d*d*d ==i)
        //        {
        //            Console.WriteLine(i);
        //        }
        //    }
        //}
    }
#endregion
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值