我正在編寫一個呼叫跟蹤應用程序,該應用程序命中了一個推送服務器,並獲取了一個JSON結果集的調用進來。在JSON對象中,有一個包含每個呼叫的logID。列表<String>不刪除項目
當新的呼叫進入時,我創建一個新的標籤頁並將一個呼叫對象與標籤頁標籤屬性相關聯。然後我檢查一個調用是否已被處置,如果推送服務器從Keys數組中刪除了logID。然後,我將Keys數組中的logIds與每個調用對象的logIds進行比較,該調用對象與每個打開的選項卡相關聯。
運行我的代碼時,它將從_psKeys列表中刪除logID,但在下一次迭代中將其添加回來。有人可以告訴我我做錯了什麼。
var jsonResult = _pushServer.GetWebRequest(_pushServer.GetNewCallUrl(_locationID, _clientID));
var jsonObject = _pushServer.GetJsonObject(jsonResult);
_tabKeys.Clear();
_psKeys.Clear();
// Load the tabKeys with all the keys for the open tabs.
foreach (TabPage tab in newCallTabControl.TabPages)
{
Call call = (Call)tab.Tag;
_tabKeys.Add(call.LogID);
}
// Load the Push Server Keys
foreach (string key in jsonObject.keys)
{
_psKeys.Add(key);
}
// Iterate over the keys and compare
foreach (string tabKey in _tabKeys)
{
foreach (string psKey in _psKeys)
{
if (! _tabKeys.Contains(psKey))
{
// Remove the tab
foreach (TabPage tabPage in newCallTabControl.TabPages)
{
Call tabCallObject = (Call)tabPage.Tag;
if (tabCallObject.LogID == tabKey)
{
newCallTabControl.TabPages.Remove(tabPage);
}
}
}
}
}
這會更好的codereview stackexchange –