Page 25 - MSDN Magazine, November 2017
P. 25
Figure 9 The Result of an Evaluation Printed to the Application Output Pad
Figure 10 Monitoring Objects with the Watch Pad
Figure 11 Monitoring Threads and Method Calls with the Threads and Call Stack Pads
pad, whose purpose is to provide a way to visually monitor vari- ables, methods and expressions. While in break mode, the Watch window is automatically enabled and you can click inside it to add a new object to monitor. Figure 10 shows an example based on a property’s value.
For each object you monitor, you can see its members and their values.Youcanalsoclickthevalue and change it, so you can see how your code behaves with a differ- ent object value. The Watch pad still provides shortcuts to the data visualizers, which you can recog- nize through the eye and pencil icons. You’ll also find other two debugging pads very useful: the Threads pad and the Call Stack pad, both visible in Figure 11.
The Threads pad shows the list of running threads and is useful for understanding the code loca- tions in which your app’s various threads are paused. It shows the
Output pad from C# code, without breaking the execution of an application. Suppose you have a .NET Core console application that waits for the user input with the following code:
string inputString = Console.ReadLine();
Debug.WriteLine($"The entered string is {inputString.Length} characters long");
The Debug.WriteLine method prints the expression to the Application Output pad, as depicted in Figure 9, without stopping application execution. In this case, the expression is an interpolated string that contains the length of the string entered by the user.
Debugging is tremendously important and Visual Studio for Mac ships with the kind of first-class debugging tools every developer needs to build high-quality applications in a productive way.
And you’re not limited to the WriteLine method; in fact, you can use all the other supported methods, such as Assert, Equals, Fail, Write, WriteIf and WriteLineIf (see bit.ly/2ydS8jO for details).
In Visual Studio for Mac, there are other ways to evaluate expres- sions and to inspect object values while debugging. You can use breakpoints and data visualizers, but you can also use the Watch msdnmagazine.com
thread ID, the name and the location of the code that refers to each thread. You can also enter a name for threads if one doesn’t exist already. The Call Stack pad shows the hierarchy of method calls, and you can enable it to also display calls to code that’s not in your solution; for example, interop frames. To accomplish this, you right-click the pad and enable the Show External Code option. By leveraging all of these, you have a complete and powerful suite of debugging tools that, together with breakpoints, the Locals pad, and data visualizer, give you deep control over your .NET Core and Xamarin solutions.
Wrapping Up
Visual Studio for Mac not only helps you build cross-platform applications for mobile devices and the cloud with Xamarin and .NET Core on macOS, it also offers all the productivity tools you need to write high-quality code. This includes productivity fea- tures in the code editor and in the debugging tools that will make you feel at home with this IDE, especially if you have experience with Visual Studio on Windows. n
AlessAndro del sole has been a Microsoft MVP since 2008. Awarded MVP of the Year five times, he has authored many books, eBooks, instructional videos and articles about .NET development with Visual Studio. Del Sole works as a senior .NET developer, focusing on .NET and mobile app development, training and consulting. He has recently authored an upcoming book called “Beginning Visual Studio for Mac” (bit.ly/2hsRxYx). You can follow him on Twitter: @progalex.
ThAnks to the following Microsoft technical expert for reviewing this article: Mikayla Hutchinson
November 2017 21