2010-05-22 63 views
0

我正在處理這種情況,我需要一些幫助。我需要提高用戶選擇信息記錄和更新用戶界面的功能的性能。我的代碼電流是改善代碼和用戶界面性能

'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

首先,您需要確定哪個部分是實際運行緩慢。這通常是使用探查器最容易實現的,但您可以僅使用Stopwatch類。

一旦你確定了緩慢的部分,然後你可以考慮如何使其更快。

作爲一個猜測,我會說最慢的部分可能是你的AddRecentViewToDB方法:我假設這是寫入數據庫。加速UI的更簡單的方法是在後臺的工作線程上實際執行該步驟。爲此,有BackgroundWorker類,使它相對容易。

如果這不是什麼導致放緩,那麼你將不得不回到上面的第一步,找出什麼是慢。

0

提高性能的一種簡單方法是不經常進行這項工作。向OnFilterChanged添加聲明,如:

' 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;