tags:

views:

74

answers:

2

I am dealing with a situation that I need some help with here. I need to improve performance on functionality that records and updates UI with user selection info. What my code current does is

'This is called to update the Database each time the user 
'makes a new selection on the UI 

Private Sub OnFilterChanged(String newReviewValueToAdd) 
    AddRecentViewToDB(newReviewValueToAdd)
    UpdateRecentViewsUI()
    PageReviewGrid.Rebind()'Call Grid Rebind    
End Sub


'This is the code that handles updating the UI with the Updated selection 
Private Sub UpdateRecentViewsUI()
    Dim rlNode As RadTreeNode = radTree.FindNodeByValue("myreviewnode")
    Dim Obj As Setting
    Dim treenode As RadTreeNode
    For i As Integer = 0 To Count - 1
        Obj = Setting.Review.Item(i)
        treenode = New RadTreeNode(datetime.now.ToString,i.ToString())
        treenode.ToolTip = obj.GetFilter
        radNode1.Nodes.Add(treenode)
    Next
End Sub
+1  A: 

First, you need to determine which is the part that is actually running slowly. This is usually most easily accomplished with a profiler, but you could event just use the Stopwatch class.

Once you've determined the slow part, then you can think about how to make it faster.

As a guess, I would say the slowest part is probably your AddRecentViewToDB method: I assume this is writing to a database. The easier way to speed up the UI is to actually perform that step on a worker thread in the background. For that, there's the BackgroundWorker class that makes it relatively easy.

If that's not what is causing the slowdown, then you'll have to go back to step one above and find out what is slow.

Dean Harding
A: 

An easy way to improve performance is to do the work less often. Add a statement to OnFilterChanged, like:

' Only do this once every 50 updates, to improve performance
if ((update_counter % 50) != 0)
{
  update_counter += 1;
  ' or do this one every second
  if (update_time_now - update_time_last_update < 1 second)
    return;
}
update_time_last_update = update_time_now;
update_counter = 0;
ChrisW