c# - What is the accepted pattern for an application that can be run as a service or as a console application -


I have a project that has been deployed as a window service for production. Although it would be useful to run as a console application for local development purposes. At the moment I have a class called ReportingHost which provides my main functionality, and a reporting service called a class which is received from servicebase and I Allows to run as a service. There is also a program class with a main method that calls ServiceBase.Run on my ReportingServiceHost.

I think I need to write a ReportingConsoleHost class allows me to run the functionality in the console, then to respond to the command line switch I want to have my main < / Code> to modify and select one or the other. These are two bits that I have trouble with.

I tried to use that code, but my app goes out immediately, it does not show a console window and it does not wait to enter before closing.

One part of the problem is that I do not have a thorough understanding of these things. A certain pattern to split my functionality, there are two different ways to run that functionality, and one main method that selects one of these methods based on the command line argument, I hope to get it I am here.

I suspect that your test project was configured as a Windows XP, extending a console not for. With a window exe console. Readline will come back immediately.

There is a console exe that works both as a service and on the command line, it is a service project visual studio) - and the environment. Add a check to user interactive - i.e

  fixed zero (main) {if (Environment.UserInteractive)} {// code starts waiting on listener and readLine} And run the // // service code, which is VS Template injection}}  

You can also use a command line switch

  • A console-mode app
  • depending on the switch


    Comments

    Popular posts from this blog

    c++ - Linux and clipboard -

    What is expire header and how to achive them in ASP.NET and PHP? -

    sql server - How can I determine which of my SQL 2005 statistics are unused? -