title: Updating Bing Map maps in concurrent environments
body: <p>I have been working over a GPS mapping application where NMEA data from a GPS (L76) development board is obtained via a serial port. The CSV data is parsed and the longitude/latitude information is then saved in a Queue. The objective is to dynamically display pushpins on a WPF-based mapping application as and when the location information is available via the serial port. </p>
  
  <pre><code>&lt;WPF:Map Name="XAMLMap" ZoomLevel="17" CredentialsProvider="the key" Mode="road" Margin="241,157,10.334,10"&gt;
  &lt;/WPF:Map&gt;
  </code></pre>
  
  <p>The application successfully displays its initial Bing Map display via the code given below:</p>
  
  <pre><code>Dispatcher.Invoke(() =&gt;
  {
      XAMLMap.CredentialsProvider = new ApplicationIdCredentialsProvider("the key");
      XAMLMap.Center = new Microsoft.Maps.MapControl.WPF.Location(50.8, -1.12222);
  
      Pushpin currentPushpin = new Pushpin();
      currentPushpin.Location = new Microsoft.Maps.MapControl.WPF.Location(50.8, -1.12222);
      XAMLMap.ZoomLevel = 18;
      XAMLMap.Margin = new Thickness(243, 151, 0, 0);
      XAMLMap.Children.Add(currentPushpin);
      mapGrid.Children.Add(XAMLMap);
  });
  </code></pre>
  
  <p>However, the actual challenge appears when the push pin Location coordinates are generated dynamically from the serial data within the following event method:</p>
  
  <pre><code>void serialPortHandler_NewSerialDataRecieved(object sender, SerialDataEventArgs e)
  {
      AddLocation(currentLocation);
  }
  
  private void AddLocation(Location location)
  {
      Dispatcher.Invoke(() =&gt;
      {
          try
          {                           
              Microsoft.Maps.MapControl.WPF.Location currentLocation = new Microsoft.Maps.MapControl.WPF.Location(location.latitude, location.longitude);
  
              Pushpin currentPushpin = new Pushpin();
              currentPushpin.Location = currentLocation;    
              XAMLMap.Margin = new Thickness(243, 151, 0, 0);                        
              XAMLMap.Children.Add(currentPushpin);
              mapGrid.Children.Add(XAMLMap);    
          }
          catch (Exception exc)
          {    
          }
      });
  } 
  </code></pre>
  
  <p>The updated coordinate latitude/longitude values are still placed properly on the map (XAMLMap). However, when the map is zoomed-out/in or panned, the map content, i.e. the roads, geographical details, resolution, do not update at all i.e. newly visible map information is not updated at all leaving a jigsaw of irregular patches. </p>
  
  <p>Also, please note that the problem has nothing to do with the way I am adding the XAMLMap object to the grid in the code above or any other children. </p>
  
  <p>I've looked into various possibilities to resolve this issue but have been unsuccessful so far. This also includes:</p>
  
  <ol>
  <li>Keeping the mapping application over a separate thread</li>
  <li>Using a timer control and using Peek method to return and display the top-most location object from the Queue</li>
  </ol>
  
  <p>Any help or direction in this regard would be highly appreciated.</p>