C# ServiceBase OnStart未从serviceController接收参数。开始

C# ServiceBase OnStart未从serviceController接收参数。开始,c#,.net,service,C#,.net,Service,据我所知,serviceBase.Onstart(args)应该接收serviceController.start(args)中存在的参数 这是我的服务控制器实现 if (serviceController.Status == ServiceControllerStatus.Stopped) { try { string[] args = {"execute-s

据我所知,serviceBase.Onstart(args)应该接收serviceController.start(args)中存在的参数

这是我的服务控制器实现

    if (serviceController.Status == ServiceControllerStatus.Stopped)
            {
                try
                {
                    string[] args = {"execute-service"};
                    serviceController.Start(args);
                    ServiceManager.WaitForStatusChange(......);
                }
                catch (InvalidOperationException ex)
                {
                    EventLog.WriteEntry(.....);
                    return 1;
                }
            }
这是我的服务

     protected override void OnStart(string[] args)
    {
        this.OnStart(args);
        this.scheduler.StartScheduler();
    }
当我尝试启动服务时,参数“execute service”不会传递给main program.cs。我有一个正在创建的日志文件,可以看到args不在那里

当我在线阅读时,正在寻找一些关于如何传递args的想法,我使用servicebase.onstart()正确地完成了这项工作


关于如何调试或修复的想法?

我认为这里没有足够的信息来调试这个问题。作为比较,这是我在设计为作为Windows服务运行的控制台应用程序中所做的:

public sealed partial class ServiceMain : ServiceBase
{
    // Service startup modes.
    private const string DEBUG = @"/d";         
    private const string INSTALL = @"/i";       
    private const string UNINSTALL = @"/u";     
然后设置ServiceMain.Main()作为启动方法:

// This is the entry point for this service. 
// This method runs on an SCM thread.
public static void Main(string[] args)
{
    if (Environment.UserInteractive && args.Length > 0)
    {
        switch (args[0])
        {
            // Debug the service as a normal app, presumably within Visual Studio.
            case DEBUG:
                ServiceMain DebugService = new ServiceMain();
                DebugService.OnStart(null);
                break;
它调用ServiceMain.OnStart()方法:


您可以看到。

谢谢RoadWarrior,我今天早上又做了一些测试,即使将ARGS添加到Service Manager的对话框中,也无法识别ARGS。今天我将做更多的故障排除。
// SCM requests service start using its own thread.
// This method must complete within 10 seconds of it
// starting. Otherwise the SCM diagnoses a hang.
protected override void OnStart(string[] args)
{
    this.AppLog = new Log();
    AppLog.Information("SCM requested service start.", "ServiceMain.OnStart");