Banner Ad

Showing posts with label CodeProject. Show all posts
Showing posts with label CodeProject. Show all posts

Sunday, February 7, 2016

Visual Studio Tips and Tricks -13 : Debugging with Visual Studio

By Francis   Posted at   3:15 PM   Visual Studio Tips and Tricks No comments
Visual Studio is a great IDE for developing all type of Microsoft desktop/web stack applications. There is no doubt on that!. One of the main feature provided in Visual Studio is it’s capability provide more options to debugging the applications. In this post I explained some basic concepts about debugging in Visual Studio.


You can also check my other Visual Studio Tips here.

Setup the environment:

In this post I’m using Visual Studio 2015 Community edition. Based on your version of Visual studio some options may differ. For simple and neat explanation, here I’m going to use a simple for loop C# code snippet.

So What is breakpoint?
When you run the program in Visual Studio IDE, if you want to check the execution of a particular routine or function at that time you can set the breakpoint. Probably, it set before to run the application. So when the program executes, the breakpoint hits and the program waits there. So that you can step into the program and take a deep look into the code and check the values there itself. This is the main advantage of breakpoints.

Set normal Breakpoint:
Set the breakpoint in an application is very simple. You can hit the F9 key or you can click on the left most border in Visual Studio. It will keep the break point on the particular line.
After setting the break point, Visual Studio indicate the particular line with the Red color and preceded with a dot like below.

Breakpoint-in-VisualStudio
Breakpoint-in-VisualStudio

In these kind of break points, it will hit without any conditions. So whenever, the execution cross the line it will simply hit there.

Set Conditional Breakpoint:
So as we discussed in the previous section,say for example, if we set the break point with in a loop it will hit the break point without any condition. So the break point is hit often. Instead of this, we may want to set some conditions. Let’s see how we can do it.

1. Right click on the break point and select “Conditions…” in the context menu.
Conditional-Breakpoint-Menu
Conditional-Breakpoint-Menu
2. Visual Studio 2015 offers the below “Breakpoint Settings” window to set up the condition.
Conditional-Breakpoint-Window
Conditional-Breakpoint-Window
3. Here I’m going to set the “Conditions” as : When the counter value(i) is greater than 5 at that time it will hit the break point. That means, till the value of the counter value is 5, it will not hit. After that it will hit.
Setting-Conditions
Set-Conditions
In some cases you may want to track based on some process id or thread id etc. Visual studio also give options for this.

Breakpoint-Window-Filter
In some cases, we want to count the “Hit count”,meant whenever the break point hits it will consider as a hitcount. You can specify it by selecting “Hit Count” list item as below:
Breakpoint-Window-HitCount
Breakpoint-Window-HitCount

Set Actions:
“Breakpoint Settings” window also offers that log message to Output window. At that you can make use of “Actions”. There are some special keywords are there, which have a special meaning when you use in the “Action” text box.

Breakpoint-Window-Action-SpecialKeyword
Breakpoint-Window-Action-SpecialKeyword
When you specify Action alone, there is a checkbox named “Continue execution”, if you check this the breakpoint will not hit. You can see the message in the “Output Window”.
Breakpoint-Window-Specify-Action
Breakpoint-Window-Specify-Action
Breakpoint-Window-Result-in-OutputWindow
Breakpoint-Window-Result-in-OutputWindow
  In the above action, we specify the special keyword "$Function", which prints the current function name as you see in the above screen shot.

Disable Break points:
In some cases, you may want to continue the execution of your program without hitting the breakpoints and later cases you may need them. At that time you can use the "Disable Breakpoint" option by using the short cut key "Ctrl + F9" key. Later cases, you can use the same short cut key to "Enable Breakpoint". You can make use of these options during run time also.

Disabled-Breakpoint
Disabled-Breakpoint
Readers, hopefully this tutorial helps you to understand about the various debugging options provided by Visual Studio. Let me know your thoughts as comments. Happy programming!



Sunday, October 25, 2015

Visual Studio : How to install Nuget packages in your project?

By Francis   Posted at   2:00 AM   Visual Studio Tips and Tricks No comments
               In this article I’m going to explain about how to install/uninstall Nuget packages for your application in Visual Studio using “Nuget Package Manager” and “Package Manager Console”. I assume that you have Visual Studio 2013/2015 on your machine.
                    Before that, if you are not aware about “Nuget” means, the below sentence is for you:
                  “NuGet is the package manager for the Microsoft development platform including .NET. The NuGet client tools provide the ability to produce and consume packages. The NuGet Gallery is the central package repository used by all package authors and consumers.”
Install Nuget Package using ‘Nuget Package Manager’:
Step 1:
Rightclick on your project and select  “Manage Nuget Packages”.


Step 2:
Now the “Nuget Package Manager” window will appear with the list of nuget packages.

Step 3:
In the search box, type the package you look for and hit enter. In this example, I just searched for “routedebugger” package and installed it by clicking the “Install” button.

Step 4:
While installing if the downloaded package tries to change the files in the solution/project it will popup the dialog to warn us. Just click “OK” for it and you can see the “installation progress” in the Output window.


Step 5:
Now you can just expand the “Solution Explore” window, see in the “Reference” to check that particular reference is added or not.

Uninstall NuGet Package using ‘Nuget Package Manager’:
Step 1:
If you want to uninstall, again go to the “Nuget Package Manager” and search for the particular package.Visual Studio automatically finds that particular package is installed on not and now you can see the “Uninstall”  button.


Step 2:
Since it made some changes in the project while installing, so it will automatically revert the changes in the file. So again it will popup the dialog. just click “OK”. Also in output window you can see the uninstall status.





Install NuGet Package using ‘Package Manager Console’:
Alternatively, you can use the “Package Manager Console” in Visual studio to install the necessary packages by running the respective command.
Step 1:

Go to www.nuget.org and type the package name in the search box and go to the particular package’s page, there you can find the “Package Manager Console” command.



Step 2:
To open the Package Manager Console, Tools –>NuGet Package Manager –> Package Manager Console.

Just copy the command from above website and paste it on the package manager console and hit enter.


Note :  Before hit enter key, just check the project name in the “Default project” dropdown. Incase, if you have lot of projects, you must pay attention on this by selecting correct project.
Uninstall NuGet Package using ‘Package Manager Console’:
Step 1:
In order to uninstall, just type the below command in the “Package Manager Console” and hit enter, it will uninstall the package: Uninstall-Package routedebugger.


That’s all! Hope this will helpful for someone!! Let me know your thoughts as comments!

Sunday, June 1, 2014

Daily interview Question #10 : what is the purpose of "explicit" implementation of interface?

By Francis   Posted at   7:32 AM   CodeProject No comments

There are 2 purposes of explicit implementation of Interface:
First, it is used to avoid name collision between interface methods. That is if you are going to create a class library, there may be a chance to use the same name in several places. At that time "explicit" implementation comes as a rescue.
Secondly, You cannot access that implemented method through the object of the class directly. Instead you typecast it as Interface reference then you can access it. This is because, the C# complier, unable to determine which one the user want to call.

Monday, April 21, 2014

File Upload Control–How to give same UI in all browsers?

By Francis   Posted at   6:56 PM   CodeProject No comments
                                  As all of know, the File Upload control is used to upload your favourite files to the server. One of the biggest challenge while using this control is UI issue. That is this control is rendered in a different ways in all browsers. Please see the below figures, each of them rendered the File Uploader in a different way. That is UI is vary across the browsers.

Sunday, April 13, 2014

ASP.Net Forums – FAQ #1 : How to enable Adsense in my site?

By Francis   Posted at   8:14 PM   Enable Adsense 1 comment
                        


This is the most frequently asked question in ASP.Net Forums. As a Adsense user (struggled with google over 6 months I got my adsense approval), I’m going to explain how to enable adsense in your website regardless of technology (either you used ASP.Net or PHP or Java etc) which you are using to built your site.

I just want to tell one thing first there is no short cut to get your adsense approval from google. Go with the below guidelines:

Connect with Us