Skip to end of metadata
Go to start of metadata

C# has the .NET framework System.Threading namespace to enable using threads. Using the namespace, one can make auxiliary threads, or “worker threads” that run in addition to the main thread of a C# program.

To create and start a thread that runs a void-returning function named “funcName”:


Making the thread and inserting the function to run can also be done in one line as so:

To make the thread sleep for 2 seconds:



To abort the thread (this stops the thread entirely):



To yield execution of the current thread to another thread that is ready to run:



To create a mutex, make a global mutex variable in the program, eg:

private static Mutex mutex = new Mutex()


To lock the mutex “mutex”, use


To unlock it, use


  • No labels