调试成功但安装后服务无法正常工作

时间:2022-01-23 22:56:23

I used the following piece of code in the service to debug the service successfully by running the service as a console application and verified everything works fine.But later when I installed the service and started it as a windows application the service is running as indicated by the services console but it is not doing the job it has to.I want to know what went wrong in this scenario.Thanks.

我在服务中使用以下代码来成功调试服务,方法是将服务作为控制台应用程序运行并验证一切正常。但是当我安装服务并将其作为Windows应用程序启动时,服务正在运行,如下所示:服务控制台,但它没有完成它的工作。我想知道在这种情况下出了什么问题。谢谢。

static void Main() { System.ServiceProcess.ServiceBase[] ServicesToRun;

static void Main(){System.ServiceProcess.ServiceBase [] ServicesToRun;

        if (Environment.UserInteractive)
        {
            ListenerSVC service = new ListenerSVC();
            service.OnStart(null);
            Console.WriteLine("Press any key to stop program");
            Console.Read();
            service.OnStop();
        }
        else
        {

            ServicesToRun = new System.ServiceProcess.ServiceBase[] { new ListenerSVC() };
            ServiceBase.Run(ServicesToRun);


        }
    }

1 个解决方案

#1


Have you tried catching/logging any exceptions? The most likely cause is security (i.e. the service account not having access to some resource). There is also often an isue locating the .config file for a service (watch that if you are using config). Finally, for simplicity, try using a command arg just in case UserInteractive is reporting incorrectly - I tend to use "-c" for console/debug mode.

您是否尝试过捕获/记录任何异常?最可能的原因是安全性(即服务帐户无法访问某些资源)。通常还有一个isue为服务定位.config文件(如果您使用的是config,请注意)。最后,为简单起见,尝试使用命令arg以防万一UserInteractive报告错误 - 我倾向于使用“-c”进行控制台/调试模式。

#1


Have you tried catching/logging any exceptions? The most likely cause is security (i.e. the service account not having access to some resource). There is also often an isue locating the .config file for a service (watch that if you are using config). Finally, for simplicity, try using a command arg just in case UserInteractive is reporting incorrectly - I tend to use "-c" for console/debug mode.

您是否尝试过捕获/记录任何异常?最可能的原因是安全性(即服务帐户无法访问某些资源)。通常还有一个isue为服务定位.config文件(如果您使用的是config,请注意)。最后,为简单起见,尝试使用命令arg以防万一UserInteractive报告错误 - 我倾向于使用“-c”进行控制台/调试模式。