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