protected void OnCalculating(CalculatingEventArgs args) { // TODO: Log progress if (Calculating != null) { Calculating(this, args); } if (args.Cancel == true) { // TODO: Log cancellation } }
public string Calculate(int digits) { StringBuilder pi = new StringBuilder("3", digits + 2); string result = null; try { if (digits > 0) { // TODO: Add Tracing around the calculation using (Tracer trace = traceMgr.StartTrace(Category.Trace)) { pi.Append("."); for (int i = 0; i < digits; i += 9) { CalculatingEventArgs args; args = new CalculatingEventArgs(pi.ToString(), i + 1); OnCalculating(args); // Break out if cancelled if (args.Cancel == true) { break; } // Calculate next 9 digits 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)); } } } result = pi.ToString(); // Tell the world I've finished! OnCalculated(new CalculatedEventArgs(result)); } catch (Exception ex) { // Tell the world I've crashed! OnCalculatorException(new CalculatorExceptionEventArgs(ex)); } return(result); }
protected void OnCalculating(CalculatingEventArgs args) { // TODO: Log progress CalculatorEventSource.Log.Calculating(args.StartingAt, args.Pi, args.Cancel); if (Calculating != null) { Calculating(this, args); } if (args.Cancel == true) { // TODO: Log cancellation CalculatorEventSource.Log.CalculationCanceled(); } }
protected void OnCalculating(CalculatingEventArgs args) { // TODO: Log progress Logger.Write( string.Format("Calculating next 9 digits from {0}", args.StartingAt), Category.General, Priority.Low, 100); if (Calculating != null) { Calculating(this, args); } if (args.Cancel == true) { // TODO: Log cancellation Logger.Write("Calculation cancelled by user!", Category.General, Priority.High, 100); } }