This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var root = Task.Delay(-1); | |
| var continuation = root.ContinueWith(t => t.GetAwaiter().GetResult(),new CancellationToken(true)); | |
| Console.WriteLine(root.IsCanceled); | |
| Console.WriteLine(continuation.IsCanceled); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static void Main() | |
| { | |
| Console.WriteLine("before start"); | |
| var task = InfiniteAsync(); | |
| Console.WriteLine("after start"); | |
| Task.WhenAll(task).Wait(); | |
| Console.WriteLine("after whenAll"); | |
| } | |
| private static async Task InfiniteAsync() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static void Main() | |
| { | |
| Task.WhenAll(A(), B()).Wait(); | |
| } | |
| private static async Task A() | |
| { | |
| Console.WriteLine(DateTime.Now + "started sync A"); | |
| Thread.Sleep(10000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class MyStack | |
| { | |
| private static Stack CurrentContext | |
| { | |
| get | |
| { | |
| return Trace.CorrelationManager.LogicalOperationStack; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal class Program | |
| { | |
| private static void Main() | |
| { | |
| var head = new Node(); | |
| CreateTree(head, 4, 2); | |
| head.Print(string.Empty, true); | |
| Console.WriteLine("Zigzag:"); | |
| var zig = new Stack<Node>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rivate static void Main() | |
| { | |
| CountToFiftyAsync().Wait(); | |
| } | |
| private static async Task CountToFiftyAsync() | |
| { | |
| var taskA = CountToAsync("a", 10); | |
| var taskB = CountToAsync("b", 10); | |
| var taskC = CountToAsync("c", 10); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void Main() | |
| { | |
| var dolly = new Sheep {DateOfBirth = new DateTime(1966, 07, 05, 11, 0, 0, DateTimeKind.Utc)}; | |
| Console.WriteLine(dolly.DateOfBirth.ToString("HH:mm:ss K")); // "11:00:00 Z" (Z means UTC) | |
| dolly = Serializer.DeepClone(dolly); // Serialize and deserialize using protobuf-net | |
| Console.WriteLine(dolly.DateOfBirth.ToString("HH:mm:ss K")); // "11:00:00" (no Z means unspecified) | |
| Console.WriteLine(dolly.DateOfBirth.ToLocalTime().ToString("HH:mm:ss K")); // "01:00:00 -10:00" (Hawaii timezone) | |
| Console.WriteLine(dolly.DateOfBirth.ToUniversalTime().ToString("HH:mm:ss K")); // "21:00:00 Z" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typeof (BclHelpers). | |
| GetField("EpochOrigin", BindingFlags.NonPublic | BindingFlags.Static). | |
| SetValue(null, new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)); | |
| var dolly = new Sheep {DateOfBirth = new DateTime(1966, 07, 05, 11, 0, 0, DateTimeKind.Utc)}; | |
| Console.WriteLine(dolly.DateOfBirth.ToString("HH:mm:ss K")); // "11:00:00 Z" (Z means UTC) | |
| dolly = Serializer.DeepClone(dolly); // Serialize and deserialize using protobuf-net | |
| Console.WriteLine(dolly.DateOfBirth.ToString("HH:mm:ss K")); // "11:00:00 Z" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void Main() | |
| { | |
| for (var i = 0; i < Environment.ProcessorCount; i++) | |
| { | |
| Task.Factory.StartNew(() => | |
| { | |
| while (true) | |
| { | |
| new Timer(_ => { }, null, TimeSpan.FromMilliseconds(100), Timeout.InfiniteTimeSpan); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal bool Change(uint dueTime, uint period) | |
| { | |
| bool success; | |
| lock (TimerQueue.Instance) | |
| { | |
| if (m_canceled) | |
| throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_Generic")); | |
| // prevent ThreadAbort while updating state |
OlderNewer