I'm using GMAP.Net library for a mapping windows application. I have about 17000 polygons on my Sql Server database. In form load event I select All polygons from database and fill a datatabale then draw polygons one by one from datatable. I also have a treeview which I add all 17000 polygon names to that treeview. Now when I check select all checkbox on treeview I call a function in Treeview node_AfterCheck event like this:
Private Sub node_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterCheck
If e.Action <> TreeViewAction.Unknown Then
Task.Factory.StartNew(Sub()
GetPolygons(e.Node)
End Sub, TaskCreationOptions.LongRunning)
End If
End Sub
Private Sub GetPolygons(node As TreeNode)
Dim objectId As String
Dim _polygon As GMapPolygon
For Each node1 As TreeNode In node.Nodes
objectId = node1.Name
For Each _polygon In polyOverlay.Polygons.AsParallel
itemTag = _polygon.Tag.ToString.Split("|")
If itemTag (0) = node1.Name Then
_polygon.IsVisible = node.Checked
Exit For
End If
Next
Next
End sub
this code takes about 40 seconds to run completely. Is there any way to optimize this code to complete in shorter time?