windows message queue and breaking out of thread

  • Thread starter Thread starter Claire
  • Start date Start date
C

Claire

(Relative newby)
Ive a secondary thread reading files from a serial port.
Ive also got a form with a progress bar informing the user on the status of
downloading the file. The progress delegate is called from the context of
the thread.
The form works fine if it's the topmost window but if it ever becomes
obscured by another application then it never gets invalidated/repainted
properly when it's redisplayed (even with lots of Thread.Sleep(0)s ).

So I thought I'd try to fix this by posting a user defined message from the
delegate to the form so that the progress message was handled in the context
of the application. (Im from a delphi background and we had to use
synchronize method of tthread when we wanted to update forms from worker
threads)

So, now I've found a Message struct and that I can overload the wndproc
function but I can't seem to find any info on the eqivalent of the
PostMessage function. Can someone help please.
 
Claire said:
(Relative newby)
Ive a secondary thread reading files from a serial port.
Ive also got a form with a progress bar informing the user on the status of
downloading the file. The progress delegate is called from the context of
the thread.

Directly, or using Control.Invoke? You mustn't update a UI element
directly from any thread other than the one which created it.

See
http://www.pobox.com/~skeet/csharp/multithreading.html#windows.forms
 
Thanks Jon,

Although you didn't answer about windows messages you've helped me
understand how to use invoke ( I searched for about an hour online about
that) I couldn't understand Microsofts help file on this method.
So I hope this solves it.

CC
 
Back
Top