public void Start() { if (!errorsInIpAndPort) { new Thread(delegate() { while (!stop) { mutex.WaitOne(); try { string tempStr; if (telnetClient.IsSocketAvailableWriting()) { telnetClient.Write("get /instrumentation/heading-indicator/indicated-heading-deg"); } else { Err = "Timeout - Heading"; } if (telnetClient.IsSocketAvailableReading()) { tempStr = telnetClient.Read(); Heading = tempStr; if (Err.Equals("Timeout - Heading")) { Err = ""; } } else { Err = "Timeout - Heading"; } if (telnetClient.IsSocketAvailableWriting()) { telnetClient.Write("get /instrumentation/gps/indicated-vertical-speed"); } else { Err = "Timeout - VerticalSpeed"; } if (telnetClient.IsSocketAvailableReading()) { tempStr = telnetClient.Read(); VerticalSpeed = tempStr; if (Err.Equals("Timeout - VerticalSpeed")) { Err = ""; } } else { Err = "Timeout - VerticalSpeed"; } if (telnetClient.IsSocketAvailableWriting()) { telnetClient.Write("get /instrumentation/gps/indicated-ground-speed-kt"); } else { Err = "Timeout - GroundSpeed"; } if (telnetClient.IsSocketAvailableReading()) { tempStr = telnetClient.Read(); GroundSpeed = tempStr; if (Err.Equals("Timeout - GroundSpeed")) { Err = ""; } } else { Err = "Timeout - GroundSpeed"; } if (telnetClient.IsSocketAvailableWriting()) { telnetClient.Write("get /instrumentation/airspeed-indicator/indicated-speed-kt"); } else { Err = "Timeout - AirSpeed"; } if (telnetClient.IsSocketAvailableReading()) { tempStr = telnetClient.Read(); AirSpeed = tempStr; if (Err.Equals("Timeout - AirSpeed")) { Err = ""; } } else { Err = "Timeout - AirSpeed"; } if (telnetClient.IsSocketAvailableWriting()) { telnetClient.Write("get /instrumentation/gps/indicated-altitude-ft"); } else { Err = "Timeout - Altitude"; } if (telnetClient.IsSocketAvailableReading()) { tempStr = telnetClient.Read(); Altitude = tempStr; if (Err.Equals("Timeout - Altitude")) { Err = ""; } } else { Err = "Timeout - Altitude"; } if (telnetClient.IsSocketAvailableWriting()) { telnetClient.Write("get /instrumentation/attitude-indicator/internal-roll-deg"); } else { Err = "Timeout - InternalRoll"; } if (telnetClient.IsSocketAvailableReading()) { tempStr = telnetClient.Read(); InternalRoll = tempStr; if (Err.Equals("Timeout - InternalRoll")) { Err = ""; } } else { Err = "Timeout - InternalRoll"; } if (telnetClient.IsSocketAvailableWriting()) { telnetClient.Write("get /instrumentation/attitude-indicator/internal-pitch-deg"); } else { Err = "Timeout - InternalPitch"; } if (telnetClient.IsSocketAvailableReading()) { tempStr = telnetClient.Read(); InternalPitch = tempStr; if (Err.Equals("Timeout - InternalPitch")) { Err = ""; } } else { Err = "Timeout - InternalPitch"; } if (telnetClient.IsSocketAvailableWriting()) { telnetClient.Write("get /instrumentation/altimeter/indicated-altitude-ft"); } else { Err = "Timeout - Altimeter"; } if (telnetClient.IsSocketAvailableReading()) { tempStr = telnetClient.Read(); Altimeter = tempStr; if (Err.Equals("Timeout - Altimeter")) { Err = ""; } } else { Err = "Timeout - Altimeter"; } if (telnetClient.IsSocketAvailableWriting()) { telnetClient.Write("get /position/longitude-deg"); } else { Err = "Timeout - Longitude"; } if (telnetClient.IsSocketAvailableReading()) { tempStr = telnetClient.Read(); if (!(tempStr.Equals("ERR"))) { // Longitude = Double.Parse(tempStr); if (Err.Equals("Timeout - Longitude")) { Err = ""; } } } else { Err = "Timeout - Longitude"; } if (telnetClient.IsSocketAvailableWriting()) { telnetClient.Write("get /position/latitude-deg"); } else { Err = "Timeout - Latitude"; } if (telnetClient.IsSocketAvailableReading()) { tempStr = telnetClient.Read(); if (!(tempStr.Equals("ERR"))) { //Latitude = Double.Parse(tempStr); if (Err.Equals("Timeout - Latitude")) { Err = ""; } } } else { Err = "Timeout - Latitude"; } // Location = new Location(Latitude, Longitude); mutex.ReleaseMutex(); Thread.Sleep(250); //SLEEP FOR 250 MS - that determines we will ask for details 4 times in a sec. } catch (Exception) { mutex.ReleaseMutex(); Err = "ERR"; Thread.Sleep(250); Err = ""; } } }).Start(); new Thread(delegate() { while (commandsQueue.Count != 0) { try { if ((!stop) && (!errorsInIpAndPort)) { if (telnetClient.IsSocketAvailableWriting()) { mutex.WaitOne(); telnetClient.Write(commandsQueue.Dequeue()); mutex.ReleaseMutex(); } else { Err = "Timeout"; } } } catch (Exception) { mutex.ReleaseMutex(); } } Thread.Sleep(250); }).Start(); } }