示例#1
0
        static int ConsumeCpu(IEnumerable<string> args)
        {
            int duration = 0;

            var options = new OptionSet()
            {
                {"duration=", v => duration = Int32.Parse(v)},
            };

            options.Parse(args);

            Stopwatch stopwatch = Stopwatch.StartNew();
            var threads = new List<Thread>();
            for (var i = 0; i < 10; i++)
            {
                var thread = new Thread(() =>
                {
                    while (duration > stopwatch.ElapsedMilliseconds)
                    {
                        var sieve = new PrimeSieve(500);
                        sieve.ComputePrimes();
                    }
                });
                threads.Add(thread);
            }
            foreach (var thread in threads) thread.Start();
            foreach (var thread in threads) thread.Join();

            return SUCCEEDED;
        }
        public ActionResult PrimeSearch(int PrimeSearchValue)
        {
            var sieve = new PrimeSieve(PrimeSearchValue);

            sieve.ComputePrimes();
            var values = sieve.ToArray();

            ViewBag.PrimeNumbers = values;

            return(View("Index"));
        }