77
1
using System;
2
using System.Threading;
3
using System.Threading.Tasks;
4
5
public class Program
6
{
7
public static void Main()
8
{
9
//DetachedTask();
10
//ParentWaitingForDetachedTask();
11
//CreatingAttachedChildTask();
12
PreventChildFromAttaching();
13
}
14
15
private static void DetachedTask()
16
{
17
var parentTask = Task.Factory.StartNew(() => {
18
Console.WriteLine("Parent task executing");
19
20
var childTask = Task.Factory.StartNew(() => {
21
Console.WriteLine("Child task executing");
22
Thread.SpinWait(500000);
23
Console.WriteLine("Child task completed");
24
});
Cached Result
Input:
Output:
Input: 5
Output: 5
Input: 1, 4, 2, 5, 3, 6
Output: 1, 4, 2, 5, 3, 6
Input: 3, 3, 3, 3, 3, 3
Output: 3, 1, 2, 4, 5, 6
Input: 6, 6, 4, 4, 2, 2
Output: 6, 1, 4, 3, 2, 5
Input: 2147483647, 2, 2147483647, 2
Output: 2147483647, 2, 1, 3
Output:
Input: 5
Output: 5
Input: 1, 4, 2, 5, 3, 6
Output: 1, 4, 2, 5, 3, 6
Input: 3, 3, 3, 3, 3, 3
Output: 3, 1, 2, 4, 5, 6
Input: 6, 6, 4, 4, 2, 2
Output: 6, 1, 4, 3, 2, 5
Input: 2147483647, 2, 2147483647, 2
Output: 2147483647, 2, 1, 3