示例#1
0
    static void Main()
    {
        // Demonstrate latch with a simple scenario: multiple
        // threads updating a shared integer. Both operations
        // are relatively fast, which enables the latch to
        // demonstrate successful waits by spinning only.
        latch.Set();

        // UI thread. Press 'c' to cancel the loop.
        Task.Factory.StartNew(() =>
        {
            Console.WriteLine("Press 'c' to cancel.");
            if (Console.ReadKey(true).KeyChar == 'c')
            {
                cts.Cancel();
            }
        });

        Parallel.Invoke(() => TestMethod(),
                        () => TestMethod(),
                        () => TestMethod());

#if LOGGING
        latch.DisplayLog();
        if (cts != null)
        {
            cts.Dispose();
        }
#endif
    }