I have to implement a trace window in my application. So I have a List (System.Collections.List<>) which serves as a buffer and a grid control which serves as trace output. As items are being added to the buffer list, I want to update my grid with the newly arrived data. So I thought of creating a thread that polls the list. This is the method to add elements:
The thread:Code:List<TraceRow> _detectedResults; public void AddToList(TraceRow row) { lock (_detectedResults) { _detectedResults.Add(row); } }
and the polling:Code:Thread readFromListThread = new Thread(ReadDataFromList); readFromListThread.Start();
The problem is, this is very slow and eats too much of the resources. Also I have a feeling that there is another way to do this...any suggestions?Code:static void ReadDataFromList() { while(true) { lock(_detectedResults) { foreach (TraceRow traceRow in _detectedResults) { FillGridControl(traceRow); } } } }




Reply With Quote