简体   繁体   English

自更新Asp.Net核心Windows服务阻止端口

[英]Self-Updating Asp.Net-Core Windows Service Blocked Port

Developing a Self-Updating Asp.Net Core Windows Service which works roughly as below: 开发一个自动更新的Asp.Net Core Windows服务,其工作原理大致如下:

  1. The Service downloads the new release and unzips it in an "update" folder 该服务下载新版本并将其解压缩到“更新”文件夹中
  2. The Service starts an Updater-Process 服务启动更新程序
  3. The Updater stops the Service and waits for the Service to finish 更新程序停止服务并等待服务完成
  4. The Updater moves the current "bin" folder to "backup" then "update" to "bin" 更新程序将当前的“ bin”文件夹移至“备份”,然后将“更新”移至“ bin”
  5. The Updater should start the Service again 更新程序应再次启动服务

The Problem 问题

On 5. the Problem occurred , that the Port am using to run my app , would be busy Even if I wait for the Port to get free like 2 minutes, it won't. 在5月5日,问题发生了,端口正在使用该端口运行我的应用程序,该端口将很忙,即使我等待端口2分钟左右的空闲时间,也不会。

But when calling the Updater "by Hand" it works just perfectly. 但是,当“手动”调用Updater时,它的工作原理非常完美。 The Port is free instantly, and the Service can be started again. 该端口立即免费,可以重新启动该服务。

The Updater gets started like this in the Service: 在服务中,更新程序将按以下方式启动:

Process process = new Process {
    StartInfo = new ProcessStartInfo(Path.Combine(parent, "VersionUpdater.exe")) {
        CreateNoWindow = true,
        UseShellExecute = false
    }
};

process.Start();

It looks like it is still connected to the Service Process, although they got different PIDs. 尽管它们获得了不同的PID,但看起来仍与服务流程保持联系。

Does anyone know how i can decouple the processes or open the port? 有谁知道我如何解耦进程或打开端口?

I found the problem: 我发现了问题:

The parent-process is waiting for the child-process so the port is still open. 父进程正在等待子进程,因此该端口仍处于打开状态。

Solution: 解:

You need to set the "UseShellExecute" to true. 您需要将“ UseShellExecute”设置为true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM