Windows服务在Debug(F5)上工作,但在安装时不工作

时间:2016-05-26 09:10:55

标签: c# windows-services

我有一个用C#编写的Windows服务,当我按下F5并生成所需的文件和目录但是当我使用installutil.exe安装它时没有任何反应(文件和目录没有生成)时工作正常。该服务安装正常,状态正在运行

尝试将日志写入文件(日志文件为空) 附加了一个调试器。 (onstart()上的点中断和初始化没有被击中) 仔细检查安装程序中的服务名称(这很好) 检查事件查看器日志(显示与.Net或服务无关)

这似乎都不能指向正确的方向,请帮助

这是代码段

     public void OnStartLive(string[] args)
        {

            Init();

        }

         private void Init()
        {
        // generates the file and directories
        }

         protected override void OnStop()
        {


            DeInit();
        }



namespace filesGerator
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {

            if (System.Environment.UserInteractive)
            {
                if (args.Length > 0)
                {
                    switch (args[0])
                    {
                        case "-install":
                            {
                                ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
                                break;
                            }
                        case "-uninstall":
                            {
                                ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
                                break;
                            }
                    }
                }
                else
                {


                        var oService = new miFileGeneratorServer();
                        oService.OnStartLive(null);
                        System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);


                }
            }
            else
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] 
            { 
                new miFileGeneratorServer() 
            };
                ServiceBase.Run(ServicesToRun);
            }
        }
    }
}

0 个答案:

没有答案
相关问题