zoukankan      html  css  js  c++  java
  • 并行+异步执行操作

     public class Program
        {
            static void Main(string[] args)
            {
                /*
                 * 具体业务中比如首页数据加载,可能需要调用多个模块
                 * 1、采用并行执行
                 * 2、耗时的操作采用异步的方法
                 */
                for (int i = 0; i < 1; i++)
                {
                    Parallel.Invoke(
                      () =>
                      {
                          Task.Factory.StartNew(() =>
                          {
                              Task.Delay(10000).Wait();
                              WaitTest();//耗时操作
                          });
                      },
                       () =>
                       {
                           for (int j = 0; j < 10; j++)
                           {
                               Console.WriteLine($"第二:{j}");
                           }
                       }                 
               );
                    Console.WriteLine("结束");
                }
                Console.WriteLine("是结束了");
                Console.ReadKey();
            }
    
            private static void WaitTest() 
            {
                Thread.Sleep(10000);
                Console.WriteLine("异步");
            }
        }
  • 相关阅读:
    CentOS 7搭建vsftp服务
    Istio
    Kubernetes
    Kubernetes
    Kubernetes
    Kubernetes
    Kubernetes
    Kubernetes
    Kubernetes
    11.树的抽象数据类型和几种表示法
  • 原文地址:https://www.cnblogs.com/macT/p/12664597.html
Copyright © 2011-2022 走看看