I could not find a direct answer to this question yet in SO. Is there a predefined delegate with void (void)
signature?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Nope. C# handles threads differently to Java. In Java, the Runnable interface is an alternative to subclassing Thread, but you still have to create a new Thread object, passing the Runnable to a constructor.
Rather than subclassing the
Thread
class, you simply create a newSystem.Threading.Thread
object and pass it aThreadStart
delegate (this is the function where you do the work). ThreadStart is the exact C# equivalent to Java's Runnable.However, the
Action
delegate has thevoid
parameters you speak of.Action has the signature you're looking for. However, it doesn't mean the same thing as Runnable does: Runnable generally indicates that the run() method is intended to be run on a Thread, while Action makes no indication. For that you'd want ThreadStart, which has the same signature, and does make that indication.
If all you need is a delegate with no parameters,
Action
is what you want. If you're dealing with threads and need to indicate the start method, useThreadStart
.The Action delegate is a void with no parameters.
http://msdn.microsoft.com/en-us/library/system.action.aspx
There are also other signatures with up to 16 parameters.