static void StartConsole() { while (true) { try { string mess = Console.ReadLine(); if (mess == "connect") { TCPClient ch = new TCPClient(); chs.Add(ch); new Thread(() => { try { ConnectEcho(ch); return; } catch (Exception) { return; } }).Start(); } else if (mess.StartsWith("!echo")) { IsInitializer = true; SendMsg(mess); } else if (mess.StartsWith("!garbage")) { gar = new Garbage(chs, true); } else { SendMsg(mess); } } catch (Exception) { // do nothing } } }
private static void ConnectEcho(Channel <string> ch) { while (true) { string msg = ch.Receive(); if (msg == null || msg == "") { continue; } else if (msg.StartsWith("!garbage")) { if (gar == null) { gar = new Garbage(chs, false); gar.Recieve(ch, msg); } } else if (msg.StartsWith("!echo")) { EchoCount++; if (parent == null && !IsInitializer) { parent = ch; parent.Send("Du er far til Skovmose"); SendEcho(msg); } if (EchoCount == chs.Count) { parent.Send(msg); } } Console.WriteLine(msg); } }