2017-05-31 36 views
0

我有一個在Winform應用程序中的日誌頁面,它顯示後臺進程並使用DataSet和DataTable將消息排序爲消息「隊列」。當發現新的進程時,會創建一個新的日誌。這工作很好,但我有內存泄漏。我一直在研究切換到「隊列」。從DataSet/DataTable遷移到隊列

(粗糙的複製/粘貼,由於複雜性和長度)

DataSet dsLogs = new DataSet("Logs"); 
.... 
[Message Queue accept new message, the following creates a new tab with an icon to click and watch queue - accept "oLogObject" from message queue] 

      if (!dsLogs.Tables.Contains(szTableName)) // add table in 
      { 
       DataTable dtNew = new DataTable(szTableName); 
       dtNew.Columns.Add("EventDate", typeof(string)); 
       dtNew.Columns.Add("Function", typeof(string)); 
       dtNew.Columns.Add("IsError", typeof(bool)); 
       dtNew.Columns.Add("LongMessage", typeof(string)); 
       dtNew.Columns.Add("Message", typeof(string)); 
       dtNew.Columns.Add("Process", typeof(string)); 
       dtNew.Columns.Add("RecID", typeof(string)); 
       dtNew.Columns.Add("Thread", typeof(string)); 
       dtNew.Columns.Add("UserName", typeof(string)); 

       MenuAdmin.btnProcessStatus NewPanel = new MenuAdmin.btnProcessStatus(); 
       NewPanel.SetProcess(oLogObject.Process); 
       NewPanel.SetThread(oLogObject.Thread); 
       NewPanel.Name = szTableName; 
       NewPanel.SetName(szTableName); 
       NewPanel.Click += NewPanel_Click; 

       dsLogs.Tables.Add(dtNew); 
      } 

      DataRow drRow = dsLogs.Tables[szTableName].NewRow(); 
      AddRow(oLogObject, szTableName); // adds the current log object to the table 

所以我和隊列的問題是,我不能使用它們與數據集,所以我不能說出/按名稱引用它們像這樣:

DataRow drRow = dsLogs.Tables[szTableName].NewRow(); 

這是可能的,這是什麼叫做這將在隊列中完成這個術語?

回答

1

隊列不能直接使用DataSet/DataTable數據。隊列是一個通用的集合(System.Collections.Generic命名空間中的.NET版本),因此您可能希望使用DataTable中定義的所有字段創建一個類(類似於AppEvent)。將新項目添加到隊列時,您將添加AppEvent類的新對象。

我希望這可以解決問題。