I am developing a windows service that is able to receive socket connection, so in the OnStart
method:
protected override void OnStart(string[] args)
{
start();
}
The start
function looks like this:
public async void Start()
{
//initialization things
...
...
TcpListener listener = new TcpListener(IPAddress.Any, port);
listener.Start();
while(true)
{
TcpClient client = await listener.AcceptTcpClientAsync().ConfigureAwait(false);
...
}
...
}
The problem is that no connection is accepted, while same code run perfect in standard command line project, I doubt there is a problem in my design, which thread runs the OnStart
method?, when control goes back to OnStart
after await
ing the accept process, is the async method ignored as it is a special case in windows service? Any suggestions is welcomed