[Solved] Named pipes in service causes high CPU usage


I can replicate your results (except 13% on my 8-core CPU). I had to download and build the AsyncPipes library from the end of this article. The problem is that the code in NamedPipeStreamClient is throwing a System.TimeoutException once per second.

In a manner of bad design, the constructor of NamedPipeStreamClient is calling a method called StartTryConnect() after setting some class members.

That method, in turn, starts a background thread which calls the method TryConnect. It goes into a tight loop here:

while (!this._Stream.IsConnected)
{
    try
    {
        ((NamedPipeClientStream) this._Stream).Connect(0x3e8);
    }
    catch
    {
    }
}

Until the server your client is trying to connect to (“ServiceToNotify”) is actually started, this is going to be the case. However, I don’t see anywhere where you have a named pipe server named that (you have the opposite, “NotifyToService”) started up.

However, once it does connect to the server, the CPU usage will drop as expected.

3

solved Named pipes in service causes high CPU usage