Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 252169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:39:20+00:00 2026-05-11T21:39:20+00:00

I have a project that is deployed to production as a windows service. However

  • 0

I have a project that is deployed to production as a windows service. However for local development purposes it would be useful to run it as a console application. At the moment I have a class Called ReportingHost that provides my core functionality, And a class called ReportingServiceHost that inherits from ServiceBase and allows me to run the application 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 that allows me to run the functionality in a console. Then I need to modify my Main to react to a command line switch and choose one or the other. These are the two bits I am having trouble with.

I have had a look at this and attempted to use that code but my app exits immediately, it doesn’t show a console window and it doesn’t wait for Enter before closing.

Part of the problem is that I dont have a deep understanding of how these things work. a definitive pattern for splitting my functionality, my two different ways of running that functionality, and a main method that chooses one of these ways based on a command line argument is what I am hoping to achieve.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:39:21+00:00Added an answer on May 11, 2026 at 9:39 pm

    I suspect your test project was configured as a windows exe, not a console exe. With a windows exe Console.ReadLine will return immediately.

    To have a console exe that works both as a service and at the command line, start it as a service project (in Visual Studio) – and add a check on Environment.UserInteractive – i.e.

    static void Main() {
        if(Environment.UserInteractive) {
            // code that starts the listener and waits on ReadLine
        } else {
            // run the service code that the VS template injected
        }
    }
    

    You can of course also use a command line switch. I have example on microsoft.public.dotnet.languages.csharp that acts as:

    • an installer / uninstaller
    • a service
    • a console-mode app

    depending on the switches

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently deployed a project into production and have run into the Invalid postback or
I have an sf1.2 based project that works in the local deployment. I deployed
I have a project that needs to be deployed on multiple servers. Its the
I have a ASP.NET MVC2 project in VS2010 that can be deployed in two
I have a project that is supposed to run on different (at least 2)
I have a project that includes a copy of phpMyAdmin. I do development locally
I have a deployed web application project that references my Utility.dll class library. I
We have an old old WinForm project that was deployed with ClickOnce. I have
There is an existing project that is already deployed in production. We want to
We have various php projects developed on windows (xampp) that need to be deployed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.