Ejemplo n.º 1
0
        private void Bw_DoWork(object sender, DoWorkEventArgs e)
        {
            Stopwatch timer = new Stopwatch();

            timer.Start();

            var next = NextNumber(FactorialInput);

            try
            {
                FactorialOutput = next
                                  .AsParallel()
                                  .WithCancellation(CancellationToken.Token)
                                  .Aggregate(BigInteger.One, (num1, num2) =>
                {
                    TotalProgressValue++;
                    return(num1 * num2);
                });
            } catch (OperationCanceledException)
            {
                TotalProgressStatus = "Cancelled";
                return;
            }

            FactorialOutputLength = FactorialOutput.ToString().Length;
            TotalProgressStatus   = "Finished";

            timer.Stop();
            TimeTaken = timer.ElapsedMilliseconds;

            IEnumerable <BigInteger> NextNumber(BigInteger num)
            {
                while (!num.IsZero)
                {
                    yield return(num--);
                }
            }
        }
Ejemplo n.º 2
0
 private void Copy()
 {
     Clipboard.SetText(FactorialOutput.ToString());
 }