Example
using System; using System.Threading; namespace Samples { public class TimeoutSample { public static void StartHere() { Console.WriteLine("Thread starting"); Thread.Sleep(1000); Console.WriteLine("Thread finishing"); } public static void Main() { Thread t = new Thread( new ThreadStart(StartHere)); Console.WriteLine("Main starting"); t.Start(); TimeSpan ts = new TimeSpan(100); Console.WriteLine("Joined: {0}", t.Join(ts)); Console.WriteLine("Joined: {0}", t.Join(Timeout.Infinite)); Console.WriteLine("Main finishing"); } } }
Main starting Thread starting Joined: False Thread finishing Joined: True Main finishing
Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.