Skip to Main Content
C# in a Nutshell
book

C# in a Nutshell

by Ben Albahari, Ted Neward, Peter Drayton
March 2002
Intermediate to advanced content levelIntermediate to advanced
864 pages
31h 8m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell

Debugger Integration

Sometimes it is useful for an application to interact with a debugger if one is present. This is done using the System.Diagnostics.Debugger class. Properties and methods on this class allow one to detect if a debugger is attached (IsAttached) and logging messages (IsLogged); launch, attach and signal a debugger (Launch); signal an attached debugger, launching one if necessary (Break); and log messages to debugger if one is attached (Log).

Additionally, there are two custom attributes (DebuggerStepThroughAttribute and DebuggerHiddenAttribute) that can be placed on methods to control how the debugger handles the method.

DebuggerStepThroughAttribute indicates to the debugger that the method should be automatically stepped through without any user interaction. This attribute is suited for use in proxies and functions where the proxy method or thunk[5] performs some trivial and/or predictable setup, calls the real method, and then performs some similarly trivial and/or predictable teardown. When single-stepping through code that calls the proxy method or thunk, the debugger automatically steps down into the real method.

When stepping through the “real” method, the call stack in the debugger still lists the proxy method or thunk. To hide it completely, use the related DebuggerHiddenAttribute attribute. These two attributes can be combined on proxies and thunks to help the user focus on debugging the application logic, not the plumbing.

void DoWork() {...} // Real method... ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# 8.0 in a Nutshell

C# 8.0 in a Nutshell

Joseph Albahari, Eric Johannsen
C# 10 in a Nutshell

C# 10 in a Nutshell

Joseph Albahari
C# in a Nutshell, Second Edition

C# in a Nutshell, Second Edition

Peter Drayton, Ben Albahari, Ted Neward
Code like a Pro in C#

Code like a Pro in C#

Jort Rodenburg

Publisher Resources

ISBN: 0596001819Catalog PageErrata