ThinkGeo.com    |     Documentation    |     Premium Support

Exception when updating an layer in multithreaded

Hi


I'm having some problems with the map control, if i make some updates to an layer, and the user make some interaction with the control at same time (layer drawing is active) the lock dosent seems to work.


FATAL..: An application error occurred.

DETAILS: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

   at ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas canvas)

   at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.x5021a7a45adbb9ee(Object x3faa3e674cef60b0)

   at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)

   at System.Threading.ExecutionContext.runTryCode(Object userData)

   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)

   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)

   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)

 


sample code of how i lock the layer.


First i remove items from the layer, and then request some new point async.


   winMap.Overlays[GetLayerName(LayerNameEnum.RepYear)].Lock.EnterWriteLock();

   try

   {

    InMemoryFeatureLayer pointLayer = (InMemoryFeatureLayer)winMap.FindFeatureLayer(GetLayerName(LayerNameEnum.RepYear));

                

    pointLayer.InternalFeatures.Clear();


    ValueStyle valueStyle = new ValueStyle();

    valueStyle.ColumnName = "RepValue";

    valueStyle.IsActive = true;


    m_themeManager.SetCurrentThemeAndParameter(m_colorThemeForm.GetSelectedTheme(), m_parameterToShow);


    for (int i = 0; i <= 100; i++)

    {

     //Color color = repLayerSettingsControl.GetColorByPercent(i);

     Color color = m_themeManager.GetCurrentColorByPercent(i);


     valueStyle.ValueItems.Add(new ValueItem(i.ToString(),

                                             new PointStyle(PointSymbolType.Circle,

                                                            new GeoSolidBrush(GeoColor.FromArgb(color.A, color.R, color.G, color.B)), 5))); 

    }

    pointLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();

    pointLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);

    pointLayer.BuildIndex();

   }

   finally

   {

    winMap.Overlays[GetLayerName(LayerNameEnum.RepYear)].Lock.ExitWriteLock();

   }


 


Code for inserting new points.


 


    winMap.Overlays[GetLayerName(LayerNameEnum.RepYear)].Lock.EnterWriteLock();

      try

      {

       InMemoryFeatureLayer pointLayer = (InMemoryFeatureLayer)winMap.FindFeatureLayer(GetLayerName(LayerNameEnum.RepYear));


       int index = 0;

       double factor = (m_currentParameterMaxValue - m_currentParameterMinValue);

       foreach (MesoRepresentativeItem item in e.Items)

       {

        index++;

        GeoCoordinate gc = ConvertFromDecimalDegreeToMeters(item.Longitude, item.Latitude);

        Feature feature = new Feature(gc.Longitude, gc.Latitude,

                                      item.GetHashCode().ToString() + index);


        int value = Convert.ToInt32(Math.Round(m_themeManager.GetCurrentPercentByValue(m_currentValues[index - 1])));

        feature.ColumnValues.Add("RepValue", value.ToString());

        pointLayer.InternalFeatures.Add(item.GetHashCode().ToString() + index, feature);

       }

       pointLayer.BuildIndex();

       pointLayer.IsVisible = true;

       Console.Out.WriteLine("Added Rep: " + e.Items.Count);

      }

      catch (Exception ex)

      {

       Console.Out.WriteLine(ex.Message);

      }

      finally

      {

       winMap.Overlays[GetLayerName(LayerNameEnum.RepYear)].Lock.ExitWriteLock();

      }


      winMap.Refresh();


 


Any idea ?



 


Lars,
 
It’s a bug for multi-thread.
 
I have fixed this bug, we can send you a temporary package tomorrow after testing it, please contact support@thinkgeo.com to require it.
 
Please let me know if you have questions
 
Thanks
James

Hi 
  
 Yes please, my workaround is to disable the exception, and let the control draw the "pig color :)",  
 I qoute ower customer, where is the pig tale :) 
  
 Best regards 
 Lars

Lars, 
  
 I have finished my testing, it works properly now in MultiThreaded. 
  
 Our support will send you the new DLL package for DesktopEdition which version is 3.1.302 
  
 Please let me know if you have more questions 
  
 James 


Lars,  
  
 Please see your FTP folder for the latest build, 3.1.302.

Hi Ryan, if you mean the customer portal, there is no update only version 3.1.299

Lars,


I have contacted one of our supports Ryan,  he will inform you of how to get the package 3.1.302.


Sorry for inconvenience.


James



Lars,  
  
 Please check your e-mail for the login information for your FTP account. You should receive an e-mail from support @ thinkgeo.com sent today.

Hi 
  
 Just tested the new 3.1.302, and the problem seems be solved, thanks for the quick response to this.

Lars, 
  
 It’s awesome you solve your problem. 
  
 Please let me know if you have more questions. 
  
 James