Minggu, 13 Desember 2015

How to debug a Windows Service written in C# flawlessly

How to debug a Windows Service written in C# flawlessly - First announced in March 2017, the Xperia L1 has come to replace Sony’s now discontinued E series. Priced at a surprisingly cheap £169, the L1 is Sony’s newest attempt at shaking up the budget phone market. Its large screen and sleek design make us think of Sony’s higher range of smartphones: it would be hard to single it out as the cheapest model in a line of Xperias. But at such a bargain price, we can’t expect it to perform as well as its more expensive counterparts. So how does the L1 hold up to other low-budget smartphones? Here’s our Xperia L1 review. first time the View branding, well we have collected a lot of data from the field directly and from many other blogs so very complete his discussion here about How to debug a Windows Service written in C# flawlessly, on this blog we also have to provide the latest automotive information from all the brands associated with the automobile. ok please continue reading:

Hi guys,

I know its been frustrating to install and uninstall and stop and start ,each and every time you have modified your windows service.



If you tried to directly Run or Press F5 ,then this will be the result from Visual Studio.

How to debug a C# written windows service

  • After creating a C# -> Windows Service project.
  • Double click "Program.cs" from the 'Solution explorer' from in VS.
  • Now change the code in function main() to the code mentioned below.
static void Main()
{
#if(!DEBUG)
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
new Service1() //Replace this with your service class name
ServiceBase.Run(ServicesToRun);
#else
Service1 myServ = new Service1(); //Replace this with your service class name
myServ.main();//This will invoke the function which contains the code you should put in OnStart when the real service runs.Just define a function called main and copy the code that you had put in OnStart. 

#endif
}

Explanation of the above code

If the Runtime configuration is set to "Debug" then the service will run as an ordinary Console application.You may set break points and debug.


If the Runtime configuration is set to anything else ,other than "Debug" then it will run as a normal service which responds to installutil and net start or stop commands.


Hope this helped you a lot in your programming career.Any comments, feel free to use the comment box below

Tidak ada komentar:

Posting Komentar