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

  • SEARCH
  • Home
  • 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 649113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:54:27+00:00 2026-05-13T21:54:27+00:00

Currently I’m checking it in the following way: if (Environment.UserInteractive) Application.Run(new ServiceControllerForm(service)); else ServiceBase.Run(windowsService);

  • 0

Currently I’m checking it in the following way:

if (Environment.UserInteractive)
    Application.Run(new ServiceControllerForm(service));
else
    ServiceBase.Run(windowsService);

It helps debugging a little and service can also be run using the executable. But assume now that the service requires interaction with the user desktop so that I have to enable “Allow service to interact with desktop” in the properties. This of course breaks this way of checking. Is there another way?

  • 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-13T21:54:27+00:00Added an answer on May 13, 2026 at 9:54 pm

    It’s not perfect, but you could probably do something like this:

    public static bool IsService()
    {
        ServiceController sc = new ServiceController("MyApplication");
        return sc.Status == ServiceControllerStatus.StartPending;
    }
    

    The idea is that if you run this while your service is still starting up then it will always be in the pending state. If the service isn’t installed at all then the method will always return false. It will only fail in the very unlikely corner case that the service is starting and somebody is trying to start it as an application at the same time.

    I don’t love this answer but I think it is probably the best you can do. Realistically it’s not a very good idea to allow the same application to run in either service or application mode – in the long run it will be easier if you abstract all of the common functionality into a class library and just create a separate service app. But if for some reason you really really need to have your cake and eat it too, you could probably combine the IsService method above with Environment.UserInteractive to get the correct answer almost all of the time.

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

Sidebar

Related Questions

Currently I insert a new relationship by everytime checking, if it doesn't exist: unless
Currently, I am writing a MiddleWare application that synchronizes information between and accounting application
Currently I'm starting a new Activity and calling finish on a current one. Is
Currently I have 2 ways of displaying images in a cell, which way will
Currently i have a node.js and socket.io application in development on my local machine
Currently have the following expression: @[TMS_Dest] + \\ + @[TMS_Rename] + (DT_WSTR,4)DatePart(yyyy, GetDate()) +
Currently I have the following Mapping in my Controller: @RequestMapping( value = /add.html, method
Currently I am using Amazon Cloudfront to service static objects on my ASP.Net MVC3
Currently I have a web service running in a tomcat (http:// localhost:8080/myApp/getUsers ). My
Currently I have a web service, which loads up any plugins located within its

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.