What is the best way to update UI from different thread?

  • Thread starter Thread starter Julia
  • Start date Start date
J

Julia

Hi,

I have an application which run 3 different thread.
the main application display a window like a console window
in VS.NET.
I would like that each thread will write to this window details about it's
progress and status.
I wonder what to choose

1.BeginInvoke.
2.Invoke-will halt the calling thread isn't it?
3.Writing to a thread safe queue,use another thread to read from the queue
and output it in the main thread

Thanks.
 
Prefer Control.BeginInvoke every time.

Using Invoke it?s not that hard to end up in a thread deadlock. And why would the calling thread want to wait around for the UI update to occur?

And as for a queue - well that?s what BeginInvoke is doing - only via the Windows message queue rather than a CLR based one.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/

Hi,

I have an application which run 3 different thread.
the main application display a window like a console window in VS.NET.
I would like that each thread will write to this window details about it's progress and status.
I wonder what to choose

1.BeginInvoke.
2.Invoke-will halt the calling thread isn't it?
3.Writing to a thread safe queue,use another thread to read from the queue and output it in the main thread

Thanks.




---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004

[microsoft.public.dotnet.languages.csharp]
 
Richard Blewett said:
Prefer Control.BeginInvoke every time.

Using Invoke it?s not that hard to end up in a thread deadlock.

Only if you don't follow the rule of "don't call Invoke while holding a
lock". It's not hard to make sure you don't deadlock, in my experience.
And why would the calling thread want to wait around for the UI update to
occur?

That's a much better reason to use BeginInvoke, of course.
 
Back
Top