Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| // <Snippet2> | |
| using System; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| public class Example | |
| { | |
| public static void Main() | |
| { | |
| var parent = Task.Factory.StartNew(() => { | |
| Console.WriteLine("Parent task executing."); | |
| var child = Task.Factory.StartNew(() => { | |
| Console.WriteLine("Attached child starting."); | |
| Thread.SpinWait(5000000); | |
| Console.WriteLine("Attached child completing."); | |
| }, TaskCreationOptions.AttachedToParent); | |
| }); | |
| parent.Wait(); | |
| Console.WriteLine("Parent has completed."); | |
| } | |
| } | |
| // The example displays the following output: | |
| // Parent task executing. | |
| // Attached child starting. | |
| // Attached child completing. | |
| // Parent has completed. | |
| // </Snippet2> |