0

I use GMap.Net and communicate with Flightgear application by UDP. Although datas are receiving by udp socket, zooming on map is generating an error which is "System.InvalidOperationException". I think udpreceive method should be synchronized with UI thread but I don't have any experience with that, how can it be? Thanks in advance.

Here is my code;

private void udpReceive(IAsyncResult ar)
        {
            byte[] udp_buffer = udp.EndReceive(ar, ref endPoint);
            string udp_message = Encoding.ASCII.GetString(udp_buffer);
            string[] udp_chunks = udp_message.Substring(0, udp_message.Length - 1).Split('|');

            fg_lat = Convert.ToDouble(udp_chunks[1]) / 1000000;
            fg_longt = Convert.ToDouble(udp_chunks[2]) / 1000000;
            fgaircraft_overlay.Clear();
            GMapMarker fgaircraft_marker = new GMarkerGoogle(
                    new PointLatLng(fg_lat, fg_longt),
                    fgaircraft_bm);
            fgaircraft_marker.Offset = new Point(-25, -22);
            Task.Run(() => fgaircraft_overlay.Markers.Add(fgaircraft_marker));
            Task.Run(()=>gmap.Overlays.Add(fgaircraft_overlay));

            fgairspeedLabel.Text = "Airspeed: " + udp_chunks[0];
            fglongitudeLabel.Text = "Longitude: " + udp_chunks[1];
            fglatitudeLabel.Text = "Latitude: " + udp_chunks[2];
            fgaltitudeLabel.Text = "Altitude: " + udp_chunks[3];
            fgrollLabel.Text = "Roll: " + udp_chunks[4];
            fgpitchLabel.Text = "Pitch: " + udp_chunks[5];
            fgheadingLabel.Text = "Heading: " + udp_chunks[6];

            udp.BeginReceive(new AsyncCallback(udpReceive), null);
        }
  • We need more info. What instruction is failing. Do you have a Stack Trace? Can you use a sniffer like wireshark or fiddler to capture udp data (or other means to get data)? Is UDP connection Closing? (sniffer or from cmd.exe >Netstat -a will indicate). – jdweng Mar 27 '20 at 16:59
  • It's not about UDP connection. When I remove "gmap.Overlays.Add(fgaircraft_overlay) " line, itis'nt generating error. Also this [link](https://stackoverflow.com/questions/43782230/c-gmap-net-generating-exception-while-plotting-5-markers-on-google-map-using-g), I have same problem but I don't understand these answer. Moreover I don't have enough reputation for add comment in this link. – Burak Berzener Mar 27 '20 at 17:10
  • All you are saying is the connection is not closing and nothing about the data going over the connection. If you send bad request then you will get back bad responses. You need to see the actual data to determine root cause. – jdweng Mar 27 '20 at 19:33

0 Answers0