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 4006304
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:29:56+00:00 2026-05-20T08:29:56+00:00

I read the MSDN article on the topic. To quote: Because a service must

  • 0

I read the MSDN article on the topic. To quote:

Because a service must be run from
within the context of the Services
Control Manager rather than from
within Visual Studio, debugging a
service is not as straightforward as
debugging other Visual Studio
application types. To debug a service,
you must start the service and then
attach a debugger to the process in
which it is running. You can then
debug your application using all of
the standard debugging functionality
of Visual Studio.

Now my problem is that my service fails to start in the first place. First it crashes, and says:

An unhandled exception
(System.Runtime.InteropServices.COMException)
occurred in MyServiceName.exe[3596])

and suggests me to debug it (the debugger instance instantly crashes when I choose one). Then it says

Could not start the MyServiceName
service on Local Computer. Error
1053: The service did not respond to
the start or control request in a
timely fashion

So, how can I investigate/debug the reason that my service won’t start? The thing is I created a console application that does EXACTLY what the service does and it works fine. (I mean I just copied the OnStart() method’s and the main loop’s contents to main).

Any help would be appreciated.

The Service is written in C# with heavy use of interop. I am using VS2008

  • 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-20T08:29:56+00:00Added an answer on May 20, 2026 at 8:29 am

    You could use a parameter to let your application decide whether to start as service or regular app (i.e. in this case show a Form or start the service):

    static void Main(string[] args)
    {
        if ((1 == args.Length) && ("-runAsApp" == args[0]))
        {
            Application.Run(new application_form());
        }
        else
        {
            System.ServiceProcess.ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] { new MyService() };
            System.ServiceProcess.ServiceBase.Run(ServicesToRun);
        }
    }
    

    Now if you pass the parameter “-runAsApp” you can debug the application normally – the SCM won’t pass this parameter, so you can also use it as service w/o any code change (provided you derive from ServiceBase)

    Edit:

    The other difference with windows services is identity (this might be especially important with InterOp) – you want to make sure you are testing under the same identity in “app” mode as well as service mode.

    To do so you can use impersonation (I can post a C# wrapper if it helps, but this can be easily googled) in app mode to use the same identity your windows service will be running under i.e. usually LocalService or NetworkService.

    If another identity is required you can add settings to the app.config that allow you to decide whether to use credentials, and if so which user to impersonate – these settings would be active when running as app, but turned off for the windows service (since the service is already running under the desired identity):

      <appSettings>
        <add key="useCredentials" value="false"/>
        <add key="user" value="Foo"/>
        <add key="password" value="Bar"/>
      </appSettings>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read the msdn article about disposing objects in http://msdn.microsoft.com/en-us/library/ee557362(office.14).aspx now I'm really confused
I have read the MSDN article on MVVM and I am not really convinced.
I've already read the MSDN article about it. It seems internally it is the
I've read the MSDN article about the layouts pass, that states: When a node
Once I read an MSDN article that encouraged the following programming paradigm (its not
I know all about this exception, read the msdn article here http://support.microsoft.com/kb/312629/EN-US/ but I
I recently read this thread on MSDN . So I was thinking of using
I read about the Conditional attribute today. According to MSDN: Applying ConditionalAttribute to a
Having read the threads Is SqlCommand.Dispose enough? and Closing and Disposing a WCF Service
I read in this article that a company has created a software capable of

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.