【问题标题】:What role does ServiceName play in Service-Designers InitializeComponent() method?ServiceName 在 Service-Designers InitializeComponent() 方法中起什么作用?
【发布时间】:2021-01-14 12:48:50
【问题描述】:

我目前正在开发一个名为 PrintWatcher 的 Windows 服务。此名称也在 serviceInstaller 属性窗口中设置。该服务工作正常,名称正确显示在任务管理器的“服务”选项卡中。 但是,在 ServiceClass Designer 中,我发现了以下内容:

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            components = new System.ComponentModel.Container();
            this.ServiceName = "Service1";
        }

将“Service1”分配给 this.ServiceName 对服务有什么影响?该名称没有显示,但不建议手动修改它,如上面的摘要中所述。 还应该在哪里设置名称?

【问题讨论】:

  • 有更新吗?请检查我的回答是否对您有帮助。

标签: c# visual-studio windows-services


【解决方案1】:

像往常一样,一个从ServiceBase类继承的windows服务类。

因此,我们需要更多地了解ServiceBase.ServiceName Property

ServiceName 向服务控制管理器标识服务。

上面链接中有一句话描述了ServiceName的作用。

另外,它说ServiceBase.ServiceName 必须与ServiceInstaller.ServiceName 相同。(这就是我们不建议您更改ServiceName 的原因)

最后,您最好查看第一个链接中的备注以了解有关 ServiceName 属性的更多信息。

【讨论】:

    猜你喜欢
    • 2022-08-04
    • 2019-10-15
    • 2010-09-19
    • 2019-07-18
    • 1970-01-01
    • 2023-03-03
    • 2020-10-02
    • 2011-03-04
    • 2019-04-02
    相关资源
    最近更新 更多