????9 ??ü????????????????
????????????Щ??????????????????StopWatch???????δ????????????????????????
????System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
????timer.Start();
????Decimal total = 0;
????int limit = 1000000;
????for (int i = 0; i < limit; ++i)
????{
????total = total + (Decimal)Math.Sqrt(i);
????}
????timer.Stop();
????Console.WriteLine(“Sum of sqrts: {0}”??total);
????Console.WriteLine(“Elapsed milliseconds: {0}”??
????timer.ElapsedMilliseconds);
????Console.WriteLine(“Elapsed time: {0}”?? timer.Elapsed);
??????????????????????????????????????????????????????????dotNetPerformance?????
????????????????????????????????????????????????????????Щ????????ο???????????
????class AutoStopwatch : System.Diagnostics.Stopwatch?? IDisposable
????{
????public AutoStopwatch()
????{
????Start();
????}
????public void Dispose()
????{
????Stop();
????Console.WriteLine(“Elapsed: {0}”?? this.Elapsed);
????}
????}
??????????using???????????????????????????δ?????????????????????????
????using (new AutoStopwatch())
????{
????Decimal total2 = 0;
????int limit2 = 1000000;
????for (int i = 0; i < limit2; ++i)
????{
????total2 = total2 + (Decimal)Math.Sqrt(i);
????}
????}
????10 ??ù??
???????????????????б??????????????????????????????μ??????????????ɡ?
????class AutoWaitCursor : IDisposable
????{
????private Control _target;
????private Cursor _prevCursor = Cursors.Default;
????public AutoWaitCursor(Control control)
????{
????if (control == null)
????{
????throw new ArgumentNullException(“control”);
????}
????_target = control;
????_prevCursor = _target.Cursor;
????_target.Cursor = Cursors.WaitCursor;
????}
????public void Dispose()
????{
????_target.Cursor = _prevCursor;
????}
????}
?????÷?????????????д??????????????????????????
????using (new AutoWaitCursor(this))
????{
????...
????throw new Exception();
????}
????????????????????????????????????????????