Unresponsive UI when using BeginInvoke

Posted by Kazoom on Stack Overflow See other posts from Stack Overflow or by Kazoom
Published on 2010-03-24T19:33:10Z Indexed on 2010/03/24 19:43 UTC
Read the original article Hit count: 237

Filed under:
|
|

Bckground
I have a networked application written in C#. my server program has a UI and several communication threads, that read from tcp sockets and display messages on controller UI.

Communication with each client is done through a seprate thread. When i recieve some stream of messages from one client , the thread for that client writes on UI, which is a richtextbox on a Form.

I call SetTextHelper(string text) method of the form.

which looks like this

private delegate void MyTextUpdateHandler(string text);
public void SetTextHelper(string text)
{
   BeginInvoke(new MyTextUpdateHandler(SetText), new object[] { text });
}

public setText(string text)
{
   richtext.Text= text;
}

Question
- If i use BeginInvoke my UI is entirely unresponsive when i m writing large stream of data to UI - Invoke solves that problem, but i read that for multi threaded environment where many thereads are sharing same resource Invoke can lead to deadlocks I share the common ichtextbox between around 16 threads - What would be a good desing for my situation?

© Stack Overflow or respective owner

Related posts about multithreading

Related posts about .NET