Home All Groups Group Topic Archive Search About

Communication between threads

Author
3 Aug 2006 4:06 AM
Jck
Could someone tell me how a thread can send data / post message to another
thread in vb.net please?

I have a main thread and a socket thread. I need a way to let the main
thread know when my socket thread receive data.

Thanks in advance!

Author
3 Aug 2006 12:15 PM
iwdu15
do you need to ghave each on different threads? the Socket class has the
ability to get data async so it wont freeze ur UI, then the socket and main
thread are on the same thread, which just makes things easier
--
-iwdu15
Author
7 Aug 2006 4:10 AM
Jck
Do you mean I need to have a timer to check the socket receive buffer size in
UI thread?

Show quoteHide quote
"iwdu15" wrote:

> do you need to ghave each on different threads? the Socket class has the
> ability to get data async so it wont freeze ur UI, then the socket and main
> thread are on the same thread, which just makes things easier
> --
> -iwdu15
Author
7 Aug 2006 4:16 AM
Tom Shelton
iwdu15 wrote:
> do you need to ghave each on different threads? the Socket class has the
> ability to get data async so it wont freeze ur UI, then the socket and main
> thread are on the same thread, which just makes things easier

That isn't really true.  The async socket calls are still executed on a
separate thread from the main thread - you just don't explicitly create
that thread, it is taken from the thread pool.

--
Tom Shelton [MVP]
Author
7 Aug 2006 6:40 AM
Jck
I still need a way for threads to communicate with each other.

Other than the Main and Socket threads, I will have some more threads such
as Printer thread and Trace log thread.

I just realize I can open a file for writing from my Main thread and let the
socket thread use the FileNumber to do any writing. However, this problem
solved if I can have the socket thread send/post a message to my Main thread.

Someone, please help!!

Show quoteHide quote
"Jck" wrote:

> Could someone tell me how a thread can send data / post message to another
> thread in vb.net please?
>
> I have a main thread and a socket thread. I need a way to let the main
> thread know when my socket thread receive data.
>
> Thanks in advance!
Author
7 Aug 2006 8:52 AM
Cor Ligthert [MVP]
Jck,

You can use any shared variable in the main and in the worker thread to use
as communication information.

Be aware that you while updating need to synclock that.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmSyncLock.asp

I like for that the queue class.

http://msdn2.microsoft.com/en-us/library/system.collections.queue.aspx

I hope this helps,

Cor

Show quoteHide quote
"Jck" <J**@discussions.microsoft.com> schreef in bericht
news:D497A8C9-0121-483E-92F6-172DBED175A7@microsoft.com...
>I still need a way for threads to communicate with each other.
>
> Other than the Main and Socket threads, I will have some more threads such
> as Printer thread and Trace log thread.
>
> I just realize I can open a file for writing from my Main thread and let
> the
> socket thread use the FileNumber to do any writing. However, this problem
> solved if I can have the socket thread send/post a message to my Main
> thread.
>
> Someone, please help!!
>
> "Jck" wrote:
>
>> Could someone tell me how a thread can send data / post message to
>> another
>> thread in vb.net please?
>>
>> I have a main thread and a socket thread. I need a way to let the main
>> thread know when my socket thread receive data.
>>
>> Thanks in advance!
Author
7 Aug 2006 3:41 PM
Brian Gideon
Messages can be sent between threads using several mechanisms.  You can
use a WaitHandle (either ManualResetEvent or AutoResetEvent) to cause a
thread to block until another thread signals an event.  You can use
Monitor.Pulse and Monitor.Wait in much the same way.  If one of your
threads is running a Windows message loop then you can use
Control.Invoke or Control.BeginInvoke.  And of course data can be
shared between threads by making sure the variables are accessible from
the code that each thread executes.  The variables themselves can even
be used a signalling mechanism.  It really depends on exactly how you
want the threads to work together.

Brian

Jck wrote:
Show quoteHide quote
> Could someone tell me how a thread can send data / post message to another
> thread in vb.net please?
>
> I have a main thread and a socket thread. I need a way to let the main
> thread know when my socket thread receive data.
>
> Thanks in advance!