![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Does .NET Support Custom Blocks? All, Does .NET support the concept of "custom" blocks? I'd like to implement some performance profiling code into an app I'm creating and I thought it would be really cool if you could do something like: profile("ProfileName") // Starts a timer { MyFunction1(); MyFunction2(); } // Ends a timer and writes it to a log The concept would be to allow me to surround a group of code with a custom block and be able to stop and start a timer based upon when it entered and exited the block. I know this could easily be accomplished by just adding a function before and after, but the block would be much more elegant. Also it would allow you to nicely accomplish the timer if for example the second line of code (MyFunction2()) returned a value. Can this be done? -alpha |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Does .NET Support Custom Blocks? Alphamacaroon <jheising@xxxxxx> wrote: Quote: > Does .NET support the concept of "custom" blocks? support. Quote: > I'd like to implement some performance profiling code into an app I'm > creating and I thought it would be really cool if you could do > something like: > > profile("ProfileName") // Starts a timer > { > MyFunction1(); > MyFunction2(); > } // Ends a timer and writes it to a log > > The concept would be to allow me to surround a group of code with a > custom block and be able to stop and start a timer based upon when it > entered and exited the block. > > I know this could easily be accomplished by just adding a function > before and after, but the block would be much more elegant. Also it > would allow you to nicely accomplish the timer if for example the > second line of code (MyFunction2()) returned a value. > > Can this be done? this - just make the returned value implement IDisposable. See http://pobox.com/~skeet/csharp/miscu...e/locking.html for an example in terms of locks. -- Jon Skeet - <skeet@xxxxxx> Web site: http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet C# in Depth: http://csharpindepth.com |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Zoom support in custom control | .NET General | |||
| Accessing custom types output from custom cmdlet's in C# GUI | PowerShell | |||
| types.custom.ps1xml for custom members | PowerShell | |||