Re: A threading problem



<nick.fletcher@xxxxxxxxxxxx> wrote in message
news:1164243206.413576.189130@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[...]
Now, I want to be able to block the sending of messages if the receive
message thread is still running. I can do this with a flag but thats
not very nice - Ive also tried using waitOne but with no joy. Anyone
got any suggestions? Many thanks

The code you posted uses two different objects for locking. So, neither
method is synchronized with the other.

If you want to synchronize the two methods, so that they cannot occur
simultaneously, they need to use a common synchronization object. Whether
this is a mutex, or a lock on a shared object, or even using a waitable
event to synchronize their efforts, the synchronization has to be through a
single object.

The question you posted is confusing for a couple of reasons:

First, in the code you posted you don't seem to be calling
OutputBuffer.SendMessages at all. But you also haven't defined
OutputBuffer.ReceiveMessages, which is what you do appear to call. So, is
it safe to assume that you actually create the OutputBuffer timer using
SendMessages? If not, why not and what is the correct code?

Second, it's not clear to me what "thread" it is you want to depend on. You
haven't created any threads. You've just created a timer that calls a
particular method on a regular basis. That happens on a thread, but there
is no "receive message thread" per se.

But hopefully, the real issue is simply that you aren't using the same
object for the send and receive as far as locking goes. If that didn't
answer your question, you might want to clarify the confusing parts of your
post.

Pete


.