添加到Linux(ARM)deamon的.NET CORE 2.1应用程序导致CPU过高



我使用的是RaspberryPi(3B+(Linux ARM IOT板,操作系统是Debian Stretch 9,我的控制台应用程序是在.NET CORE 2.1上开发的。

我的应用程序非常简单,只需打开到远程服务器的几个TCP连接,在构建应用程序(使用符号Linux ARM(后,我可以看到输出文件包括myAppmyApp.dll。我已经通过直接命令行运行了很多:

pi@raspberrypi:~/Desktop/myApp $ ./myApp

或:

pi@raspberrypi:~/Desktop/myApp $ dotnet ./myApp.dll

运行良好,通过top的CPU(进程名为myApp,而后者为dotnet(均小于20

今天,我想将我的应用程序添加到守护程序中,以便一直运行,这是我在/etc/systemd/system:下的守护程序服务文件

[Unit]
Description=myApp for controlling Tcp devices
[Service]
WorkingDirectory=/home/pi/Desktop/myApp
# 
ExecStart=/usr/local/bin/dotnet myApp.dll
Restart=always
# Restart service after 10 seconds if this service crashes:
RestartSec=10
SyslogIdentifier=myApp
# User=pi
[Install]
WantedBy=multi-user.target

enable, start之后,通过systemctl命令的服务,我可以看到应用程序正在通过top运行(进程名称为dotnet(,但现在CPU相当高(对于进程dotnet(,超过了100。

你知道CPU是如何上升的吗?有没有办法让我的进程名而不是dotnet

最后我发现原因是Main:中的代码

static void Main(string[] args)
{
//my business logic code
//balabala
while (true)
Console.ReadLine();
}

这意味着在deamon模式下,Console.ReadLine()总是可以读取一个空间并导致无限循环,这消耗了CPU,我不确定这个空间是怎么来的,这是.NET CORE错误吗?

最新更新