Hi Alex
Thanks again.
[color=blue]
> I would stick with BeginInvoke. As I see it you need to check how your[/color]
trace
That was the unhappy conclusion I was coming to. I look forward to the time
when forms and controls are thread-safe ;-)
Charles
"AlexS" <salexru2000NO@SPAMsympaticoPLEASE.ca> wrote in message
news:Ov2AiVbTEHA.3512@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hi, Charles
>
> I would stick with BeginInvoke. As I see it you need to check how your[/color]
trace[color=blue]
> is implemented. If you really need to sequence it, you can use some
> collection object (Queue, Stack, Hashtable - whatever), to post events in
> correct order and then to extract them for display in correct order.
> DataReceived event won't solve the problem by itself.
>
> If I get your situation, you can keep the sequence of sent data, but[/color]
answers[color=blue]
> might be not sequenced properly? Possibly you need some contraption to[/color]
link[color=blue]
> your send to your receive. For example, you can save send somewhere or[/color]
pass[color=blue]
> it to receiving thread. Then when you receive answer you can show both[/color]
using[color=blue]
> BeginInvoke. Or you can link the answer to original send and show the link
> in your trace. Depends.
>
> It's not very clear for me what is "everything is synchronized". By itself
> raising event between the threads is same as raising event on same thread.
> Except of course threads synchronization issues. Which are different from
> yours.
>
> HTH
> Alex
>
> "Charles Law" <blank@nowhere.com> wrote in message
> news:%23zJ$CgYTEHA.2416@TK2MSFTNGP09.phx.gbl...[color=green]
> > Hi Alex
> >
> > Thanks for the reference. I have been trying with Invoke, and more[/color]
> recently[color=green]
> > BeginInvoke, but they both have their problems.
> >
> > Invoke does not return until the UI thread is free, which causes[/color][/color]
deadlock[color=blue][color=green]
> > when the UI thread is waiting for the worker thread to do something.
> >
> > BeginInvoke returns immediately, but the UI is not updated until the[/color]
> thread[color=green]
> > is free, which means that updates can occur out of sequence. In[/color]
> particular,[color=green]
> > I send data out of the serial port and produce a trace in a window
> > on-screen. When replies are sent, I add them to the trace. The trace of[/color]
> the[color=green]
> > received data is invoked from an event raised by the worker/comms[/color][/color]
thread.[color=blue][color=green]
> > When there are a lot of exchanges of outgoing and incoming data, the
> > outgoing data is added to the trace first, and then the incoming data,[/color][/color]
and[color=blue][color=green]
> > thus the correct sequence is lost.
> >
> > I was looking for a way for the comms class to raise its 'DataReceived'
> > event on the UI thread, so that everything would be synchronised. Any[/color]
> ideas?[color=green]
> >
> > Charles
> >
> >
> > "AlexS" <salexru2000NO@SPAMsympaticoPLEASE.ca> wrote in message
> > news:u%233d5iXTEHA.2692@TK2MSFTNGP09.phx.gbl...[color=darkred]
> > > Charles,
> > > Take a look at examples at
> > >
http://msdn.microsoft.com/msdnmag/is...Multithreading and in[/color][/color]
> MSDN[color=green][color=darkred]
> > > also, if you haven't seen them yet
> > >
> > > "Charles Law" <blank@nowhere.com> wrote in message
> > > news:%23JCrt6WTEHA.3844@TK2MSFTNGP11.phx.gbl...
> > > > Suppose a worker thread needs to signal to the main thread that an[/color][/color]
> event[color=green][color=darkred]
> > > has
> > > > occurred. Ordinarily, any event raised by the worker thread will be[/color][/color][/color]
on[color=blue][color=green]
> > its[color=darkred]
> > > > own thread.
> > > >
> > > > How can the worker thread raise an event on the main thread instead?
> > > >
> > > > TIA
> > > >
> > > > Charles
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]