Banner Ad

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!



Wednesday, January 6, 2016

Replace Special character from string using Regular expression in C#

By Francis   Posted at   6:04 PM   CodeSnippets No comments
In one of the forum post, the poster asked to
  1. Remove all the special character
  2. Then Remove the space and replace with _ (underscore) character
Say for example, if he gave, the input string as “Levi Jeans (Blue) & yellow 101 – 150Ah” and the output he wants as “Levi_Jeans_Blue_yellow_101_150ah”.
Solution:

            string yourInput = "Levi Jeans (Blue) & yellow 101 - 150Ah"; 
            Regex rgx = new Regex(@"[^a-zA-Z\d\s]"); 
            // Replace Special Charater and space with emptystring 
            string finalOutput = rgx.Replace(yourInput,""); 
            Console.WriteLine(finalOutput); 
            Regex rgx1 = new Regex("\\s+"); 
            // Replace space with underscore 
            finalOutput = rgx1.Replace(finalOutput, "_");

Monday, January 4, 2016

Open Live Writer–An alternative for Windows Live writer

By Francis   Posted at   4:55 PM   Open Live Editor No comments
                          Open Live Writer

                     For the last couple of year, i have used a windows essential tool called “Windows Live Writer” for blogging. Yes! It’s made my job easier. It reduces huge amount of work regarding formatting, insert images etc., in my blog post. Literally, I’m a big fan of it.
                        But most recently, Google changed it’s authentication mode and adopt a new authentication technique. So whenever you tried to post/publish a draft you will get the below error:
WindowsLiveEditor_Issue
                         As a remedy, I Googled and Binged a lot and find an another alternative called “Open Live Writer”. You can download it from here. It’s a opensource editor, developed by a group of people inside and outside (.NetFoundation) Microsoft. If you want to participate you can get the source from: https://github.com/OpenLiveWriter/OpenLiveWriter. If you want to know about more Scott Hanselman’s post is very much helpful, which discusses removed features and features on the way in OLW etc.,

                          One of the main draw back that I found in OLW(Open Live Editor) is, it missed out the “Automatic spell check”, which I thought all bloggers love that. Another good news is you can run OLW and Windows Live Editor side by side.As a tweak for the “Spell Check Issue”, I’m still uses Windows Live Editor to draft my blog and publish it by OLW. Hope this tweak is still worth mentioning! wlEmoticon-smile[2]

Hope this post will help for someone! Smile

December Month Winner in C# Corner

By Francis   Posted at   11:37 AM   CSharpCorner No comments
                       DecemberMonthWinner


                                 I’m very much happy to announce that, I’m also one of the monthly winner in C#Corner for the month December 2015. This month award is something special to me since third time in a row, I received this award. I’m very much happy and thankful to all of my readers,friends and colleague who are all always improves me a lot!

Sunday, January 3, 2016

Got My New Year Gift : Officially CSharpCorner MVP

By Francis   Posted at   10:57 AM   MVP No comments
                              CSharpCorner_MVP_2016
                            I’m very much happy to announce that I got awarded as C# Corner MVP for 2016. I officially received a mail from C# Corner on 2nd Jan 2016. I believe this is one of my biggest milestone achievement in my carrier, since this is my first MVP award. This award really induce me more to achieve new heights within ASP.Net community. Without my family support this award is not possible, especially my Mother, Dad, “Lovely” Wife and my Son “LittleMaster” Subin. My hearty thanks to C# Corner Team, Friends and my colleagues!!! Congrats to all the other winners also,
                   Personally, I want to dedicate this award to my close “late” friend SathyaSeelan. Really i miss you Sathya, I believe you are always with me!
Connect with Us