Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Does .NET Support Custom Blocks?

Reply
 
Old 05-12-2008   #1 (permalink)
Alphamacaroon


 
 

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 SpecsSystem Spec
Old 05-12-2008   #2 (permalink)
Jon Skeet [C# MVP]


 
 

Re: Does .NET Support Custom Blocks?

Alphamacaroon <jheising@xxxxxx> wrote:
Quote:

> Does .NET support the concept of "custom" blocks?
Well, you're not really after .NET support here so much as language
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?
A using statement would probably be the easiest way of accomplishing
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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46