Search code examples
c#delegatesfirst-class-functions

C# version of Java Runnable? (delegate?)


I could not find a direct answer to this question yet in SO. Is there a predefined delegate with void (void) signature?


Solution

  • 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, use ThreadStart.