I am a junior developer using the .NET framework.
I am dealing with a problem because my GUI freezes when I run my application with a lot of data loading.
I have a grid as an output text box for writing strings. The grid has a row for each expected message.
The application then receives the messages, and the grid updates the cell in the row that corresponds to the message. In addition, I write a line in the text box with information about the message.
For example, a text field will have messages such as:
10:23:45 Message 1 arrived and the result is OK
10:23:45 Message 2 arrived and the result is OK
10:23:45 Message 3 arrived and the result is FAIL
10:23:45 Message 4 arrived and the result is OK
10:23:46 Message 5 arrived and the result is OK
....
And the grid will look something like this:
MESSAGE_ID | RESULT <------- HEADER
Message_1 | OK
Message_2 | FAIL
Message_3 | OK
Message_4 | OK
Message_5 | OK
Message_6 | Waiting
Message_7 | Waiting
....
, , , , . , , .
, - , ? GUI?
, BackgroundWorker, GUI - , , , , .
EDITED1:
:
1) . GUI, BlockingQueue.
private BlockingQueue _guiQueue = new BlockingQueue(1000);
2) Thread1
, , :
_guiQueue.Enqueue(new UpdateResult(_message.Name, _message.Result));
BlockingQueues, :
http://www.codeproject.com/KB/recipes/boundedblockingqueue.aspx
, Main Thread , Grid output, .
public MainThread(IMainForm mainView)
{
_mainView = mainView;
....
_guiQueue = new BlockingQueue(1000);
....
logger.Debug("Initializing Timer");
_timer = new DispatcherTimer();
_timer.Interval = TimeSpan.FromMilliseconds(10);
_timer.Tick += HandleMessages;
_timer.Start();
...
logger.Debug("Launching OPThread");
_orderPassingThread = new OPThread(_OPQueue, _commonObjects);
_orderPassingThreadProcess = new Thread(new ThreadStart(_orderPassingThread.OPThreadProcess));
_orderPassingThreadProcess.Start();
...
}
private void HandleMessages(Object sender, EventArgs args)
{
Presenter.Messages.Message message;
while ((message = _guiQueue.Dequeue(10)) != null)
{
switch (message.MessageType)
{
case messageTypes.updateResult:
UpdateResult updateStepMsg = (UpdateResult) message;
_mainView.updateStepResult(updateStepMsg.Name, updateStepMsg.Result);
break;
....
default:
break;
}
}
}
}
, .
, STOP, , , GUI
!
PS: DevExpress, - XtraGrid, - memoEdit