C#

Articles on C# programming language.

Creating Custom Debug Visualizer in C#

Debug Visualizers are visual studio IDE’s debugging component. These components represent the variables and class objects in meaningful form so that it can be easily visualised. Say; for example, you have class ABC to store the “Passport Size” photo of a person and using the visualizer you can see the photo of the person while debugging the object of ABC. In this example, we will create our own visualizer to see the Stack data structure. You can use the technique explained here with any objects.

The Item marked as 1 show five elements pushed into the Stack object of the Dot Net Framework. Item marked as two shows the Visual studio debugger showing the Visualizer written by us. If we write multiple visualizers for the same Stack object, C# debugger lists them all here. Moreover, we can mention the default one by placing the check mark. Clicking the lens icon invokes that default visualizer. The item marked as three shows the simple stack debug visualizer which lists all the current items in the stack. Left is the Top of the Stack and right is the bottom of the stack.

C# Debugger Attributes Explained

In the last example, we saw about Logging and getting function call stack data. In this article, we will see about Debugger Attributes which controls debugging behavior of the objects and gives a rich experience to the debugging user. An Attribute is a Tag set over the elements like Class, Functions, assemblies, etc. These tags work out how the elements should act at run time. Let us see below specified debugging attributes with a simple example:

DebuggerBrowsable Attribute
DebuggerDisplay Attribute
DebuggerHidden Attribute

Debugging Using C# System.Diagnostics

The text box marked as 1, shows the status of the debugger. When we attach the application with the debugger, the status shows Attached. Clicking the Refresh button (Marked as 2) updates the debugger status. Clicking the Break on Code button (Marked as 3) dynamically breaks the application as breakpoint is hit. This is useful when you want to break the application without the manual insertion of breakpoints. When we click the Debug Log (marked as 4) button, the example produces the log entries in the debug output window. In the same debug output window, we print the application call stack whenever user clicks the Output Stack Trace button (Marked as 5).

ASP.Net Master Page Example

Master Pages help in providing the consistently laid-out pages. When we switch between other pages, we can note the steady look and feel throughout the websites. Microsoft provides Master Page support from ASP.Net 2.0 onward. The Master Page is used to making the outer skeleton structure of the websites and we can see this outer skeleton as web page header, footer and sidebars with navigational elements. In this example, we will explore how to create a Master page along with other web pages.

Creating Custom Performance Counter in C#

The Register and Leave button share same Performance Counter called Register Click and Update button uses a one more Counter called Update Click. This example form increments the Counters Register Click and Update Click when user clicks the relevant buttons Register and Update. The Leave button will reduce the Register Click performance count by one. This example looks hollow. But it is just for a tryout purpose.

In the real case, these kinds of click counts are useful to measure Performance of the Operator. Say, for example, a click count on the print button measures how many billing is done in an hour by an operator on the billing counter of a retail shop. The perfmon can plot the graph over time, showing how many billing a billing counter staff clears. You can think of a better example than this one once you know how this Example works.