public void StartControl(string IP) { Task.Run(() => { try { OMGcontrolClient = new TcpClient(IP, 2112); } catch { return; } if (OMGcontrolClient.Connected) { ControlStart?.Invoke(); } OMGcontrolStream = OMGcontrolClient.GetStream(); try { var RO = ReadRootObject(OMGcontrolStream); Task.Run(() => SentInform?.Invoke(RO)); } catch { ControlEnd?.Invoke(); } try { using (ControlClient = new TcpClient(IP, 2113)) { using (NetworkStream stream = ControlClient.GetStream()) { RigInform RO; while (ControlClient.Connected) { RO = ReadRootObject(stream); Task.Run(() => SentInform?.Invoke(RO)); } ControlEnd?.Invoke(); } } } catch { ControlEnd?.Invoke(); } }); }
public void StartInformStream(string IP) { if (!Streaming) { Streaming = true; Task.Run(() => { try { Client = new TcpClient(IP, 2111); if (Client.Connected) { StreamStart?.Invoke(); } using NetworkStream stream = Client.GetStream(); RigInform RO; Task.Run(() => { while (App.Live && Client.Connected && Streaming) { Thread.Sleep(2000); Task.Run(() => { try { Client2114?.Close(); Client2114?.Dispose(); Client2114 = new TcpClient(IP, 2114); using NetworkStream stream = Client2114.GetStream(); byte[] data = new byte[1]; int bytes = stream.Read(data, 0, data.Length); OMGAlive = true; } catch { Client2114?.Close(); Client2114?.Dispose(); } }); } Exit(); }); Task.Run(() => { Thread.Sleep(5000); asdf: while (App.Live && Client.Connected && Streaming) { if (OMGAlive) { OMGAlive = false; for (int i = 0; i < 6; i++) { Thread.Sleep(1000); if (OMGAlive) { goto asdf; } } Exit(); } } Exit(); }); while (App.Live && Client.Connected && Streaming) { RO = ReadRootObject(stream); Task.Run(() => SentInform?.Invoke(RO)); Thread.Sleep(50); } Exit(); } catch { Exit(); } }); } }