开发者

C# multithreaded server. pass object to main thread

开发者 https://www.devze.com 2023-02-22 07:29 出处:网络
I have very little experience with threading, and I have googled this for hours without figuring this out.

I have very little experience with threading, and I have googled this for hours without figuring this out.

I followed this tutorial: http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server

Wh开发者_运维问答at is the best way to pass an object from the threads that handle client communication to the main thread. I just want to pass simple data such as who is connected and who sent what message.

Thanks in advance


Well you can use simple synchronization, but that would cause contention in the connection threads, so you can use a queue or similar.

For example :http://en.wikipedia.org/wiki/Producer-consumer_problem

You have an example in C# here : http://www.yoda.arachsys.com/csharp/threads/deadlocks.shtml

0

精彩评论

暂无评论...
验证码 换一张
取 消