private static async Task WorkloadAsync()
        {
            await Primes.FromRangeAsync(1, 100_000, CancellationToken.None);

            Countdown.Signal();
            await Task.Delay(10_000);

            Primes.FromRange(1, 1_000);
        }
        static void Main()
        {
            Console.WriteLine("Hello TPL!");
            var sw = new Stopwatch();

            sw.Restart();

            var task = Task.Run(() => Primes.FromRange(1, 200_000));

            task.Wait();
            var primes = task.Result;

            sw.Stop();
            var elapsed = sw.Elapsed;

            Console.WriteLine($"Found {primes.Count} primes after {elapsed}");
        }
Exemple #3
0
        static void Main()
        {
            Console.WriteLine("Hello TPL!");
            var sw = new Stopwatch();

            sw.Restart();

            Task <List <int> > task1 = Task.Run(() => Primes.FromRange(1, 100_000));
            Task <List <int> > task2 = Task.Run(() => Primes.FromRange(100_000, 150_000));
            Task <List <int> > task3 = Task.Run(() => Primes.FromRange(150_000, 200_000));

            Task.WaitAll(task1, task2, task3);
            int primesCount = task1.Result.Count + task2.Result.Count + task3.Result.Count;

            sw.Stop();
            var elapsed = sw.Elapsed;

            Console.WriteLine($"Found {primesCount} primes after {elapsed}");
        }
        static void Main()
        {
            Console.WriteLine("Hello TPL!");
            var sw = new Stopwatch();

            sw.Restart();

            Task <List <int> > task     = Task.Run(() => Primes.FromRange(1, 200_000));
            Task <int>         contTask = task.ContinueWith(prevTask =>
            {
                var count = prevTask.Result.Count;
                Console.WriteLine($"Found {count} primes");
                return(count);
            });

            int primesCount = contTask.Result;

            sw.Stop();
            var elapsed = sw.Elapsed;

            Console.WriteLine($"Found {primesCount} primes after {elapsed}");
        }