c# - 如何设置多个 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)
{
}
}
}
其中一项服务:
请帮帮我..我不知道该怎么办了...
解决方案
推荐阅读
- kubernetes - 无法从集群外部访问 EKS NodePort 服务
- amazon-web-services - 强制 Terraform 在 AWS Elasticache Redis 集群上应用挂起的更改
- python - python:返回概念
- flutter - 扩展一个小部件真的是一种反模式吗?
- sql - 以 YYYY-MM-DD 格式获取一年前的最后一天
- android - 我想编写一次代码并在多个平台(Windows、Linux、Mac、Android、iOS)上运行它。有没有与此相关的编程语言?
- javascript - 从 material-ui 的 TextField 打印 React 中的值
- sap-cloud-sdk - 如何在 SAP Cloud SDK Java 中调用本地 BAPI
- python - AttributeError: 'int' object has no attribute 'append' 我的列表有简单的问题
- perl - 如何使用 Test::More 在 perl 程序中测试 subs 而不会丢失程序退出代码?