Friday, 18 November 2011

Adding SYNTAXHIGHLIGHTER in Blog..

How to add SYNTAXHIGHLIGHTER to your blog.?
for adding syntaxhighlighter in our blog we need to apply some changes to our blog template...
1) Frist of all select your blog and go to design.
2) there select Template it will show your selected template.
3) then go to edit html of your template


4) it will ask for confirmation for editing html directly select proceed
5) it will show one text area contain design of your template there you need to search this tag
</head> use Ctrl + F to find this tag



6) now use this block of javascript and link and past it just above the </head>



7) now select save template and it will close the edit html window.


8) now syntax highlighter will added to your blog..
9) for using syntax highlighter to highlight your syntax use pre tab like this...
<pre class="brush:c-sharp"> 
  // your code will be placed between this pre tag 
</pre> 
for more information on brush type please see this link...
http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/
10) Now its done enjoy...!!!!!


Saturday, 12 November 2011

Debug or Test your Windows Service Without Installing it...!!!

Introduction

When you develop a Windows Service and want to run or debug it, you get a message box with this message:

Cannot start service from the command line or a debugger.
A Windows Service must first be installed (using installutil.exe)
and then started with the ServerExplorer, Windows Services 
Administrative tool or the NET START command.

So for testing you have to first install it on your computer, but it is a long process and also boring because every time you make changes, you have to reinstall your service and test it again.

Solution

For debugging or testing your service without installing it, make changes in Program.cs
static class Program
{
    static void Main()
    {
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] 
        { 
            new MyService() 
        };
        ServiceBase.Run(ServicesToRun);
    }
}
Change it to: 

static class Program
{
    static void Main()
    {
        #if(!DEBUG)
           ServiceBase[] ServicesToRun;
           ServicesToRun = new ServiceBase[] 
           { 
               new MyService() 
           };
           ServiceBase.Run(ServicesToRun);
         #else
           MyService myServ = new MyService();
           myServ.Process();
           // here Process is my Service function
           // that will run when my service onstart is call
           // you need to call your own method or function name here instead of Process();
         #endif
    }
}

After adding #if and #else to your main fuction, now when you press F5 or run your service, it will not show you the previous message and simply run, so attach a break point to your method which will be called by the service when it will start. Using this, you can simply debug your service without installing it.

For this no need to add any extra using directive (like using System.Data or using System.IO) to your class file. It will simply as it is.

Enjoy!!!