C#中的多线程和异步程序之间的区别 [英] Difference between Multithreading and Async program in c#

查看:944
本文介绍了C#中的多线程和异步程序之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初在Stackoverflow和google中搜索了类似类型的问题.只有一个链接提出了一些观点,但我不清楚. [ 1 ]

I have initially searched in Stackoverflow and google for a similar type of question. Only one link gave some points, but I can't understand clearly. [1]

以下问题困扰着我

  1. 在异步编程中,什么是真正的回调方法?是 代表?

  1. In Asynchronous programming, what is real Callback method? is delegate?

异步程序的主要功能是使用多线程吗?

The implent of async program is using multi threads?

如果提供图片进行说明,我将非常感谢

If provided with graphics to explain, I would be very grateful

["多线程与异步编程之间的区别"

[1] "Difference between Multithreading and Asynchronous programming"

推荐答案

单线程阻塞

要了解异步/并发/多线程,我们需要从最基础的知识入手,为什么我们要为这个问题增加很多复杂性.

Single Threaded Blocking

To understand asynchronous/concurrent/multi-threaded we need to start with the most basics and WHY we add so much complexity to the issue.

开始时,只有真正的单线程阻塞应用程序.这些都是非常简单的程序,而且很有可能是您现在正在编写的程序.

In the beginning there was only really Single Threaded Blocking applications. These are really simple programs, and more than likely, these are what you are writing right now.

为了解释,我将使用一个比萨饼屋的比喻.

To explain, I will use an analogy of a Pizza House.

想象一下,您的计算机是一个只有一位员工的比萨饼店.他只接受过基础训练.

Imagine your computer is a pizza house with a single employee. He has only had basic training.

您走进商店,与员工交谈,查看菜单并订购披萨.

You walk into the shop, talk with the employee, look at the menu and order a pizza.

太好了.员工走进商店的后方,将披萨放在上方的 中,然后站在烤箱旁边等待披萨煮熟.

Great. The employee walks into the back of the shop, puts a pizza in the over and stands next to the oven waiting for the pizza to cook.

您记得您的妻子不喜欢菠萝.您对试图引起他的注意以更改您的订单的员工大喊大叫.没有骰子.他不会从烤箱里跳出来(他睡着了).

You remember your wife doesn't like pineapples. You shout at the employee trying to get his attention to change your order. No dice. He will not budge from the oven (he fell asleep).

你会生气而离开.

您去下一家披萨店.

它有4名员工.

您走进商店,与员工交谈,查看菜单并订购披萨.

You walk into the shop, talk with the employee, look at the menu and order a pizza.

他向背后的其他员工大喊(发送消息),使您成为披萨.他们把一个放进烤箱.他站在烤箱旁边,睡觉.

He shouts (sends a message) to the other employees in the back to make you a pizza. They put one in the oven. He stands next to the oven, and sleeps.

您忘记了您的妻子对培根过敏.您告诉员工A取消披萨.他向厨师大喊大叫,叫醒了他.厨师将比萨饼扔进垃圾桶,然后将犹太洁食比萨饼放入烤箱.他很快就睡着了.

You forget your wife has allergies to bacon. You tell employee A to cancel the pizza. He yells inside to the cook, wakes him up. The cook throws the pizza in the bin and puts a Kosher pizza in the oven. He falls back asleep promptly.

等一下,披萨准备好了,您会得到帐单.公司规模庞大(雇用了太多员工,其中一半在工作中睡觉).

You wait, pizza is ready, you get a bill. Its massive (hiring too many staff, and half of them sleep on the job).

您去下一家披萨店.

它有1名员工.

您走进商店,与员工交谈,查看菜单并订购披萨.

You walk into the shop, talk with the employee, look at the menu and order a pizza.

他走进去,在烤箱里放了一个比萨.然后,他将收据( 回叫 )附加到比萨饼上.他走回柜台.

He walks inside, puts a pizza in the oven. He then attaches the receipt (callback) to the pizza. He walks back out to the counter.

您还记得您妻子本月实际上不吃肉.您告诉员工,他进去了,解决了这个情况.

You remember your wife actually doesn't eat meat this month. You tell the employee, he goes inside, fixes the situation.

在员工检查完内部的披萨之后.然后,他读了收据(将此披萨交给鲍勃).

After the employee checks inside for a done pizza. He then reads the receipt (give this pizza to Bob).

您会得到便宜的负担得起的响应式披萨.

You get cheap affordable and responsive pizza.

这篇关于C#中的多线程和异步程序之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆