static void Main(string[] args) { OnStartup(); try { Task.Factory.StartNew(() => { server.Listen(); }); } catch (Exception ex) { server.Disconnect(); Console.WriteLine(ex.Message); } Console.ReadLine(); }