|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Communication between threadsCould 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! 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 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 iwdu15 wrote:
> do you need to ghave each on different threads? the Socket class has the That isn't really true. The async socket calls are still executed on a> 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 separate thread from the main thread - you just don't explicitly create that thread, it is taken from the thread pool. -- Tom Shelton [MVP] 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! 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! 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!
Unique an array of strings
Co-existing ASP.NET 1.1 and 2.0??? Accessing Structure Members Transactions through Remoting Simple xpath question Function doesn't return a value on all code paths *** Using DataReaders to populate combo boxes - please help!!! *** Monitor Software Installation Changes surpress newline on Enter press Moving windows |
|||||||||||||||||||||||