c#中异步和并行编程之间的关系是什么? [英] what is the relation between Asynchronous and parallel programming in c#?

查看:24
本文介绍了c#中异步和并行编程之间的关系是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑,因为异步编程是一种异步执行代码块的方法,它调用一个方法而不等待结果.同样,并行编程是一种同时执行多个任务的方法,但所有这些任务都是异步执行的.所以想知道/困惑这两种 C# 编程范式之间的关系是什么.

I am getting confused as asynchronous programming is a way to execute a block of code asynchronously, that calls a method and doesn't wait for the result. In the same way, parallel programming is a way to execute more than one task simultaneously, but all those tasks are executed asynchronously. So wondering/confused what is the relationship between these two programming paradigms in c#.

推荐答案

并行编程 是一种我们使用多线程更快地执行任务的技术.这意味着在现代多核架构上,我们可以利用更多可用资源来执行任务.

Parallel programming is a technique where we use multiple threads to execute a task faster. This means that on modern multi-core architectures we can utilize more of the resources available to perform a task.

一个很好的例子是使用快速排序对列表进行排序.

A great example of this is sorting a list using quicksort.

通常对于并行编程,性能很重要并且所有线程都在为一个共同的目标工作.

Normally with parallel programming, performance is important and all the threads are working to a common goal.

异步编程略有不同.这通常涉及运行时间较长的任务和可能正在等待某种外部刺激的任务.一个很好的例子是在后台线程中执行大型计算,以便 UI 保持响应.对于异步代码,我们通常指的是与主应用程序以不同速率执行的代码.

Asynchronous programming is subtly different. This normally involves longer running tasks and tasks which are perhaps waiting on some kind of external stimuli. A good example of this is to perform a large calculation in a background thread so that the UI remains responsive. With asynchronous code we are normally talking about code which executes at a different rate to our main application.

这篇关于c#中异步和并行编程之间的关系是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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