首页 > 解决方案 > 如何设置多个 Windows 服务?

问题描述

所以,我正在创建一个 Windows 服务,并且我正在关注这个视频来设置 Windows 服务。

https://www.youtube.com/watch?v=tAF9krJu3cs

所以,我有一个模型,我在控制器中获取模型,这样我就可以构建我想要发送的内容,然后,我在服务上调用该控制器。之后,我创建了安装程序。问题:我有 3 个并且我能够创建它们添加: [RunInstaller(true)] 在每个服务的开始。在那之后,我说它们不是手动的,而是为错误“准备”它们,启动它们,然后我启动它们。但是,我打开其中一个,另一个关闭,依此类推。一段时间后我能够打开 3(也许这是一个错误),但它们都再次停止工作......我的代码:

项目安装程序:

在此处输入图像描述

ProjectInstaller.Designer.cs:

{
    partial class ProjectInstaller
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
            this.AccountService = new System.ServiceProcess.ServiceInstaller();
            this.FinInfoPrevYearService = new System.ServiceProcess.ServiceInstaller();
            this.GetFinancialInfoService = new System.ServiceProcess.ServiceInstaller();
            // 
            // serviceProcessInstaller1
            // 
            this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalService;
            this.serviceProcessInstaller1.Password = null;
            this.serviceProcessInstaller1.Username = null;
            this.serviceProcessInstaller1.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.serviceProcessInstaller1_AfterInstall);
            // 
            // AccountService
            // 
            this.AccountService.ServiceName = "AccountService";
            this.AccountService.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.AccountService_AfterInstall);
            // 
            // FinInfoPrevYearService
            // 
            this.FinInfoPrevYearService.ServiceName = "FinInfoPrevYearService";
            this.FinInfoPrevYearService.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.FinInfoPrevYearService_AfterInstall);
            // 
            // GetFinancialInfoService
            // 
            this.GetFinancialInfoService.ServiceName = "GetFinancialInfoService";
            this.GetFinancialInfoService.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.GetFinancialInfoService_AfterInstall);
            // 
            // ProjectInstaller
            // 
            this.Installers.AddRange(new System.Configuration.Install.Installer[] {
            this.serviceProcessInstaller1,
            this.AccountService,
            this.FinInfoPrevYearService,
            this.GetFinancialInfoService});

        }

        #endregion

        private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
        private System.ServiceProcess.ServiceInstaller AccountService;
        private System.ServiceProcess.ServiceInstaller FinInfoPrevYearService;
        private System.ServiceProcess.ServiceInstaller GetFinancialInfoService;
    }
}

项目安装程序.cs:

{
    [RunInstaller(true)]
    public partial class ProjectInstaller : System.Configuration.Install.Installer
    {
        public ProjectInstaller()
        {
            InitializeComponent();
        }

        private void serviceProcessInstaller1_AfterInstall(object sender, InstallEventArgs e)
        {

        }

        private void AccountService_AfterInstall(object sender, InstallEventArgs e)
        {

        }

        private void GetFinancialInfoService_AfterInstall(object sender, InstallEventArgs e)
        {

        }

        private void FinInfoPrevYearService_AfterInstall(object sender, InstallEventArgs e)
        {

        }
    }
}

其中一项服务:

在此处输入图像描述

请帮帮我..我不知道该怎么办了...

标签: c#windowsweb-servicesservice

解决方案


推荐阅读