委托和线程之间的区别 [英] difference between delegate and thread

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

问题描述

委托和线程之间的区别?

Difference between delegate and thread?

推荐答案

线程和委托是不同的构造.

托管代码中的委托是其他语言中的函数指针.代表允许我们按需执行方法,以帮助我们实现后期绑定.委托维护自己的一组参数,这些参数在调用该委托时由客户端传递.

线程是进程中的另一条路径.每个线程通常负责维护自己的异常处理程序,优先级集和自己的上下文.线程是操作系统的重要构造.
Threads and delegates are different constructs.

A delegate in managed code is a function pointer in other languages. Delegates help us in achieving late binding by allowing us to execute methods on demand. A delegate maintains its own set of parameters that are passed by the client when this delegate is called.

A thread is a different path in a process. Each thread is generally responsible for maintaining its own exception handlers, a priority set and its own context. Threads are an important construct for the Operating System.


线程和委托是两个完全独立的东西.委托就像一个函数的变量.在其他语言中,它们称为函数指针.这些变量可以引用一个或多个函数.线程允许在应用程序中同时存在多个执行路径.因此,您可以在应用程序中同时做一件事.
Threads and delegates are two completely seperate things. A delegate is a like a variable for a function. In other languages they are called function pointers. These variables can reference one or more functions. Threads allow for multiple execution paths to in application to exist at the same time. So you can be doing more than one thing at the same time in your application.


代理确实有局限性,因为它们使用公共线程池,但是它们使异步编程变得容易得多.除非您需要的线程多于线程池中可用的线程,或者需要对线程执行进行更精确的控制,否则请绝对使用委托.
Delegates do have limitations, as they use the common thread pool, but they make asynchronous programming so much easier. Unless you need more threads than are available in the thread pool, or need more precise control over thread execution, definitely use delegates.


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

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