This should come as an advice to Xdr and any other guy willing to learn.
The server's meta-entry point:
Code:
static async void Server() {
}
Should not be called like this from the Main method:
Code:
Task.Factory.StartNew(() => Server());
//or not even:
Task.Run(() => Server());
Because: async and await should be used for little operations which need to be done on a background thread, preferably in the Thread Pool. But if the Thread Pool is full, then the operation will be moved on a newly created thread, which isn't OK.
If you overuse the thread pool with long-term operations, it would lose its sense (which is: supporting queueing short-term operations).
Just use a thread, which will do the job a lot better:
Code:
...
(Program.serverThread = new Thread(() => Server())).Start();