// Start the server private void Start() { // Creates a new thread for the server _serverThread = new Thread(Listen) { Name = "OCTGN.net Server" }; // Flag used to wait until the server is really started var started = new ManualResetEvent(false); // Start the server _serverThread.Start(started); _broadcaster.StartBroadcasting(); started.WaitOne(); }
public async Task Start() { if (_listenTask != null) { throw new InvalidOperationException("Server already started."); } _broadcaster.StartBroadcasting(); _tcp.Start(); Log.Info("Waiting for first connection"); using (var cancellation = new CancellationTokenSource(TimeSpan.FromMinutes(1))) { cancellation.Token.Register(() => _tcp.Stop()); await ListenSingle(); Log.Info("Got first connection"); } _listenTask = Listen(); }