Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Same application which runs as a service but also a user launchable program.

  • 20-09-2012 8:15pm
    #1
    Registered Users, Registered Users 2 Posts: 7,501 ✭✭✭


    I came across an application today which ran as a windows service but also if ran by the user launched a GUI.

    I can't find much on how to accomplish this via c#.

    Anyone know?


Comments

  • Registered Users, Registered Users 2 Posts: 2,040 ✭✭✭Colonel Panic


    You are the worst at Google!

    In main
    if (Environment.UserInteractive)
    {
       Console.WriteLine("Now it's a console app. Or it could be a WinForms or WPF app");
       service.StartInteractive();
       Console.ReadLine();
       service.StopInteractive();
    }
    else
    {
       ServiceBase[] ServicesToRun;
       ServicesToRun = new ServiceBase[] { service };
       ServiceBase.Run(ServicesToRun);
    }
    

    Skeleton service
    internal class MyService : ServiceBase
    {
    
       protected override void OnStart(string[] args)
       {
          // Your startup stuff
          base.OnStart(args);
       }
       
       protected override void OnStop()
       {
          // cleanup
          base.OnStop();
       }
       
       public void StartInteractive()
       {
          OnStart(null);
       }
       
       public void StopInteractive()
       {
          OnStop();
       }
    }
    


  • Registered Users, Registered Users 2 Posts: 7,501 ✭✭✭BrokenArrows


    hummm.

    Thats easier than i expected it to be.

    Surely not the worst at google.
    Im sure people who use yahoo are worse. lol

    Thanks.


Advertisement