Coffeehouse Thread

2 posts

Windows Services Problem

Back to Forum: Coffeehouse
  • User profile image
    Ion Todirel

    i have a Windows Service (default settings), with this code inside OnStart method:

    protected override void OnStart(string[] args)
    {
        TextWriter
    tw = new StreamWriter(@"C:\test_service.txt", true);
        tw
    .WriteLine("Service started at: " + DateTime.Now.ToString());
        tw
    .Close();
    }

    in ServiceProcessInstaller, Account = LocalService (or NetworkService), what code should i have in OnStart method to run service? (without warning: The ... service on Local Computer started and then stopped. Some services stop automatically if they have no work to do. for example, the Performance Logs and Alerts service.)

    don't tell me change Account to LocalSystem.

  • User profile image
    JPeless

    Well, if the file isn't written, it is likely a permission issue for the localservice account in the C:\ root.

    Other than that your service would start, write the file, and stop, because I believe the thread is done...

    If you want it to keep going you need to have a thread still going... I usually kick off worker threads for the services I have written.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.