jkh
jkh

Reputation: 3678

Stop Windows Service waiting on AcceptTcpClient

I have a Windows service that listens for connections with

TcpClient client = myTcpListener.AcceptTcpClient();

I am wondering what happens when this Windows service is stopped while waiting to accept a new connection.

Will the listener still be listening for connections on that port? If so, how can I kill this listener?

Upvotes: 1

Views: 1146

Answers (3)

zmbq
zmbq

Reputation: 39013

When the process dies, the listener will obviously not be listening anymore.

You should clean it up properly as mentioned by ChrisWue.

Upvotes: 0

Vinicius Saeta
Vinicius Saeta

Reputation: 183

It's the same behavior of a thread. The process only ends when threads finish. When you run the stop method, close all connections manually.

Upvotes: 0

ChrisWue
ChrisWue

Reputation: 19020

You should call Stop() on the listener. Note that you need to close accepted connections separately.

Upvotes: 2

Related Questions