MultiThread and UI Forms update

  • Thread starter Thread starter cybertof
  • Start date Start date
Hi,

It's not impossible to update UI from another thread, but it is strongly
advised not doing so as it can lead to odd behaviour and corrupted data.
As a general rule, only communicate with UI from the UI thread!

Happy coding!
Morten Wennevik [C# MVP]
 
Hi,

It's a SAFE practice do not do what the writers of the code say not to do,
it may work in some circunstance, even most of the times, but when you find
thatsingle case where it does not work you will break you head trying to
figure out why it does not work as expected.

If you do as they say you can be 100% sure it will WORKS ALWAYS, if not it
may FAIL SOMETIMES.

Cheers,
 
cybertof said:
I have changed the 2 thread code to make them interact directly with the
UI Form elements.

It works !

In which cases this would not work ?

in any case, at any time. It really depends what you are trying to do, with
which control and on which platform. But when the problem happens, it may be
really hard to debug if you are not aware of this issue. To avoid loosing
hours or days trying to debug such stupid problems, always use the Invoke
method when you are updating you UI from another thread.
 
Hi,

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

It's a SAFE practice do not do what the writers of the code say not to do,
it may work in some circunstance, even most of the times, but when you find
thatsingle case where it does not work you will break you head trying to
figure out why it does not work as expected.

If you do as they say you can be 100% sure it will WORKS ALWAYS, if not it
may FAIL SOMETIMES.

That is what people call 'the path of least resistance'. Ditch the guns,
and nobody will get shot ;-)

Ciao
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top