惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
Y
Y Combinator Blog
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
S
SegmentFault 最新的问题
J
Java Code Geeks
V
Visual Studio Blog
H
Help Net Security
Stack Overflow Blog
Stack Overflow Blog
aimingoo的专栏
aimingoo的专栏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
B
Blog RSS Feed
The Cloudflare Blog
MyScale Blog
MyScale Blog
月光博客
月光博客
Microsoft Security Blog
Microsoft Security Blog
美团技术团队

博客园 - Beewolf

MarkdownToMediaWiki AI时代开发的开发流程 Blazor下的serilog Oracle From VS2019 TO VS2022问题处理 PLINQ实现Map/Reduce模式 学习 基于微软的RDP远程桌面共享排错 oracle vs2019 edmx 更改 CentOS 7安装odoo 15 删除ELK的索引 ELK故障处理,不知道成功否 软件开发的SOLID原则 阿里云的远程桌面问题 Zabbix增加邮箱后Server宕处理 201811招投标培训要点 openvas scanner 服务未启动修复 Hacker一月间 U盘安装kali中CDROM问题解决 测量衰老 tensorFlow小结 tensorFlow可以运行的代码
异步编程
Beewolf · 2022-08-05 · via 博客园 - Beewolf

学习了一下:C#多线程编程实战。好书!

网上看了大量的async、await资料,还是不明白,直到看了一位兄弟发的https://www.cnblogs.com/MrHanBlog/p/11848728.html,才有点开阔。

程序员还是得多动手才行。

using System;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
namespace Chapter1.Recipe1
{
	class Program
	{
        private static async Task Test()
        {

            Console.Out.WriteLine(2);
            Task.Run(() =>
            {
                Thread.Sleep(2000);
                Console.WriteLine(20);
            });
            GetV();
            Console.Out.WriteLine(21);
            Console.Out.WriteLine(6);
            Console.Out.WriteLine(22);
        }
        private static async Task GetV()
        {
            Console.Out.WriteLine(3);
            Task.Run(() =>
            {
                Thread.Sleep(1000);
                Console.WriteLine(33);
            });
            await Task.Run(() =>
            {
                Thread.Sleep(10000);
                Console.WriteLine(4);
            });
            Console.Out.WriteLine(5);

        }

        static void Main(string[] args)
        {

            Console.Out.WriteLine(1);
            Test();
            Console.Out.WriteLine(7);
            string str = Console.ReadLine();
        }

    }
}

  输出理解了,就理解含义了。

1
2
3
21
6
22
7
33
20
4
5

很有意思啊,编程。