简体   繁体   中英

Self-Updating Asp.Net-Core Windows Service Blocked Port

Developing a Self-Updating Asp.Net Core Windows Service which works roughly as below:

  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"
  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.

But when calling the Updater "by Hand" it works just perfectly. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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