public static void CalcPi1(int digits) { StringBuilder pi = new StringBuilder("3", digits + 2); if (digits > 0) { pi.Append("."); for (int i = 0; i < digits; i += 9) { int nineDigits = NineDigitsOfPi.StartingAt(i + 1); int digitCount = Math.Min(digits - i, 9); string ds = string.Format("{0:D9}", nineDigits); pi.Append(ds.Substring(0, digitCount)); } } }
void worker_DoWork(object sender, DoWorkEventArgs e) { lblStatus.ForeColor = Color.Black; labelMethod.Text = "CPU Bound - BW"; var sw = Stopwatch.StartNew(); // time the operation var digits = Convert.ToInt32(_digits.Value); StringBuilder pi = new StringBuilder("3", digits + 2); if (_worker.CancellationPending == true) { e.Cancel = true; return; } if (digits > 0) { pi.Append("."); for (int j = 0; j < digits; j += 9) { int nineDigits = NineDigitsOfPi.StartingAt(j + 1); int digitCount = Math.Min(digits - j, 9); string ds = string.Format("{0:D9}", nineDigits); pi.Append(ds.Substring(0, digitCount)); _pi.Text = pi.ToString(); if (_worker.CancellationPending == true) { _pi.AppendText("<<Cancelled>>"); e.Cancel = true; return; } _worker.ReportProgress(j); } } textBoxPerformance.Text = Convert.ToString(sw.Elapsed); e.Result = 100; }
private static string DoWork(decimal workAmount) { // int value = 1; var digits = Convert.ToInt32(workAmount); StringBuilder pi = new StringBuilder("3", digits + 2); if (digits > 0) { pi.Append("."); for (int j = 0; j < digits; j += 9) { int nineDigits = NineDigitsOfPi.StartingAt(j + 1); int digitCount = Math.Min(digits - j, 9); string ds = string.Format("{0:D9}", nineDigits); pi.Append(ds.Substring(0, digitCount)); } } return(pi.ToString()); }