fork(2) download
  1. using System;
  2. using System.Threading;
  3.  
  4. class Program {
  5. public static void DoWork() {
  6. Console.WriteLine("Child thread starts");
  7.  
  8. Console.WriteLine("Child thread goes to sleep");
  9. Thread.Sleep(5000); // the thread is paused for 5000 milliseconds
  10. Console.WriteLine("Child thread resumes and finishes");
  11. }
  12.  
  13. public static void Main(string[] args) {
  14. ThreadStart childJob = new ThreadStart(DoWork);
  15. Console.WriteLine("Main thread starts");
  16.  
  17. Thread childThread = new Thread(childJob);
  18. childThread.Start();
  19.  
  20. Console.WriteLine("Main thread waiting");
  21. childThread.Join();
  22. Console.WriteLine("Main thread finishes");
  23. }
  24. }
Success #stdin #stdout 0.01s 199104KB
stdin
Standard input is empty
stdout
Main thread starts
Child thread starts
Child thread goes to sleep
Main thread waiting
Child thread resumes and finishes
Main thread finishes