# Drawing Lines using InMemoryFeatureLayer very slow

**URL:** <https://community.thinkgeo.com/t/drawing-lines-using-inmemoryfeaturelayer-very-slow/1818>\
**Category:** WinForms\
**Created:** [October 25, 2011, 6:41am UTC](https://community.thinkgeo.com/t/drawing-lines-using-inmemoryfeaturelayer-very-slow/1818 "2011-10-25T06:41:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dana](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/9de053/32.png) [@Dana](https://community.thinkgeo.com/u/Dana)\
**Post date:** [October 25, 2011, 6:41am UTC](https://community.thinkgeo.com/t/drawing-lines-using-inmemoryfeaturelayer-very-slow/1818/1 "2011-10-25T06:41:46Z")

</div>

I&nbsp;am&nbsp;drawing&nbsp;up&nbsp;to&nbsp;500&nbsp;lines&nbsp;at&nbsp;a&nbsp;maximum&nbsp;rate&nbsp;of&nbsp;20&nbsp;lines&nbsp;per&nbsp;second.&nbsp;I&nbsp;found&nbsp;that&nbsp;the&nbsp;map&nbsp;display&nbsp;is&nbsp;getting&nbsp;slower&nbsp;when&nbsp;the&nbsp;updates&nbsp;is&nbsp;that&nbsp;fast.

Any&nbsp;suggestions&nbsp;on&nbsp;how&nbsp;to&nbsp;solve&nbsp;this&nbsp;performance&nbsp;issue&nbsp;?

Attaced&nbsp;is&nbsp;my&nbsp;code.

Public&nbsp;Sub&nbsp;Draw\_Line(ByVal&nbsp;Ref,&nbsp;ByVal&nbsp;LongBeg,&nbsp;ByVal&nbsp;LatBeg,&nbsp;ByVal&nbsp;LongEnd,&nbsp;ByVal&nbsp;LatEnd,&nbsp;ByVal&nbsp;Layer,&nbsp;ByVal&nbsp;Label,&nbsp;ByVal&nbsp;Colour,&nbsp;ByVal&nbsp;LineType,&nbsp;ByVal&nbsp;Linewidth)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;sysColour&nbsp;As&nbsp;System.Drawing.Color&nbsp;=&nbsp;System.Drawing.ColorTranslator.FromOle(Colour)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;geoColour&nbsp;As&nbsp;GeoColor&nbsp;=&nbsp;GeoColor.FromArgb(sysColour.A,&nbsp;sysColour.R,&nbsp;sysColour.G,&nbsp;sysColour.B)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;valueStyle&nbsp;As&nbsp;New&nbsp;ValueStyle()  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;valueStyle.ColumnName&nbsp;=&nbsp;"Line"

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;valueItem&nbsp;As&nbsp;New&nbsp;ValueItem()  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;valueItem.DefaultAreaStyle.OutlinePen.Color&nbsp;=&nbsp;geoColour  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;valueItem.DefaultLineStyle.OuterPen.Color&nbsp;=&nbsp;geoColour  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;valueItem.DefaultLineStyle.OuterPen.Width&nbsp;=&nbsp;Linewidth  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;valueItem.Value&nbsp;=&nbsp;CStr(Ref)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;valueStyle.ValueItems.Add(valueItem)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;inMemoryLayer&nbsp;As&nbsp;InMemoryFeatureLayer&nbsp;=&nbsp;CType(WinformsMap1.FindFeatureLayer(Get\_Layer(Layer)),&nbsp;InMemoryFeatureLayer)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inMemoryLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel&nbsp;=&nbsp;ApplyUntilZoomLevel.Level20  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inMemoryLayer.Open()  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inMemoryLayer.Columns.Add(New&nbsp;FeatureSourceColumn("Line"))  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inMemoryLayer.Close()

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;lineShape&nbsp;As&nbsp;New&nbsp;LineShape()  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lineShape.Vertices.Add(New&nbsp;Vertex(LongBeg,&nbsp;LatBeg))  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lineShape.Vertices.Add(New&nbsp;Vertex(LongEnd,&nbsp;LatEnd))  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lineShape.Id&nbsp;=&nbsp;CStr(Ref)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;newFeature&nbsp;As&nbsp;Feature&nbsp;=&nbsp;New&nbsp;Feature(lineShape)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newFeature.ColumnValues.Add("Line",&nbsp;CStr(Ref))  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inMemoryLayer.InternalFeatures.Add(newFeature)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WinformsMap1.Refresh(WinformsMap1.Overlays())

&nbsp;&nbsp;&nbsp;&nbsp;End&nbsp;Sub

---

<div class="post-metadata">

**Author:** ![Val](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/e56c9b/32.png) [@Val](https://community.thinkgeo.com/u/Val)\
**Post date:** [October 25, 2011, 9:49am UTC](https://community.thinkgeo.com/t/drawing-lines-using-inmemoryfeaturelayer-very-slow/1818/2 "2011-10-25T09:49:19Z")

</div>

Dana,&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;By&nbsp;looking&nbsp;at&nbsp;your&nbsp;code,&nbsp;I&nbsp;think&nbsp;that&nbsp;the&nbsp;inefficiency&nbsp;might&nbsp;come&nbsp;from&nbsp;the&nbsp;fact&nbsp;that&nbsp;you&nbsp;are&nbsp;refreshing&nbsp;the&nbsp;map&nbsp;each&nbsp;time&nbsp;you&nbsp;are&nbsp;calling&nbsp;the&nbsp;function&nbsp;Draw\_Line.&nbsp;If&nbsp;you&nbsp;are&nbsp;calling&nbsp;that&nbsp;function&nbsp;20&nbsp;times&nbsp;in&nbsp;a&nbsp;second&nbsp;and&nbsp;you&nbsp;are&nbsp;refreshing&nbsp;the&nbsp;map&nbsp;each&nbsp;time,&nbsp;this&nbsp;is&nbsp;going&nbsp;to&nbsp;cause&nbsp;a&nbsp;performance&nbsp;issue.&nbsp;It&nbsp;would&nbsp;make&nbsp;more&nbsp;sense&nbsp;to&nbsp;call&nbsp;WinformsMap1.Refresh()&nbsp;only&nbsp;one&nbsp;time,&nbsp;once&nbsp;you&nbsp;have&nbsp;added&nbsp;all&nbsp;the&nbsp;new&nbsp;features&nbsp;to&nbsp;your&nbsp;inMemorFeatureLayer.&nbsp;I&nbsp;hope&nbsp;this&nbsp;tip&nbsp;is&nbsp;going&nbsp;to&nbsp;help.

---

<div class="post-metadata">

**Author:** ![Dana](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/9de053/32.png) [@Dana](https://community.thinkgeo.com/u/Dana)\
**Post date:** [October 26, 2011, 5:56am UTC](https://community.thinkgeo.com/t/drawing-lines-using-inmemoryfeaturelayer-very-slow/1818/3 "2011-10-26T05:56:02Z")

</div>

Hi&nbsp;Val,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;the&nbsp;feedback.&nbsp;I&nbsp;agree&nbsp;with&nbsp;your&nbsp;observation.&nbsp;&nbsp;The&nbsp;implementation&nbsp;of&nbsp;an&nbsp;external&nbsp;refresh&nbsp;timer&nbsp;to&nbsp;"bulk"&nbsp;refresh&nbsp;newly&nbsp;drawn&nbsp;lines&nbsp;should&nbsp;work.&nbsp;&nbsp;I&nbsp;kind&nbsp;of&nbsp;hoped&nbsp;that&nbsp;there&nbsp;is&nbsp;an&nbsp;"auto-refresh"&nbsp;mechanism&nbsp;for&nbsp;such&nbsp;scenarios.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Dana

---

<div class="post-metadata">

**Author:** ![Val](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/e56c9b/32.png) [@Val](https://community.thinkgeo.com/u/Val)\
**Post date:** [October 26, 2011, 8:54am UTC](https://community.thinkgeo.com/t/drawing-lines-using-inmemoryfeaturelayer-very-slow/1818/4 "2011-10-26T08:54:53Z")

</div>

Dana,

&nbsp;I&nbsp;am&nbsp;glad&nbsp;I&nbsp;could&nbsp;point&nbsp;you&nbsp;to&nbsp;the&nbsp;right&nbsp;direction.&nbsp;We&nbsp;don't&nbsp;have&nbsp;an&nbsp;"auto-refresh"&nbsp;mechanism&nbsp;because&nbsp;we&nbsp;can&nbsp;never&nbsp;assume&nbsp;at&nbsp;what&nbsp;point&nbsp;some&nbsp;changes&nbsp;should&nbsp;be&nbsp;reflected&nbsp;on&nbsp;the&nbsp;map.&nbsp;Thank&nbsp;you.
