为什么要使用ThreadStart?
有人可以解释一下我们为什么使用 ThreadStart 吗?
new Thread (new ThreadStart (Update)).Start(); -Versus-
new Thread (Update).Start(); // Seems more straightforward
private void Update() { }
Can somebody please clarify why we use ThreadStart?
new Thread (new ThreadStart (Update)).Start(); -Versus-
new Thread (Update).Start(); // Seems more straightforward
private void Update() { }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不必这样做。如果这样做,只有您能说出原因...
从 C# 2 开始,方法组(即通过名称引用方法)可以隐式转换为具有相同签名的委托。由于
Thread
构造函数采用ThreadStart
,因此您可以向其传递一个与ThreadStart
具有相同签名的方法组。You don't have to. If you do, only you can say why...
Since C# 2, method groups (i.e. references to a method via its name) are implicitly convertible to delegates with the same signature. Since the
Thread
constructor takes aThreadStart
, you can pass it a method group with the same signature asThreadStart
.您不必在示例中使用它。
ThreadStart 是一个对象,其中包含可用于启动线程的函数。
例如,如果您有一个要启动的函数列表,将它们放入列表中,然后循环它们,则可以使用它。
You don't have to use it in your example.
ThreadStart is an object that holds a function that can be used to start a thread.
You'd use it for example if you have a list of functions which you want to start, put them in a list, and loop through them.