Advertisement

.NET BeginReceive problems (multithreading)

Started by May 13, 2004 02:47 PM
2 comments, last by AndyGeers 20 years, 8 months ago
I wonder if anybody can help me out here: I''m using C# to try and write a chat program, but I think multithreading is causing me problems. Basically, I''m using the Socket.BeginReceive method to generate callbacks whenever data arrives from the server, but it seems that if the server sends too quickly then I lose data --- the callback is called once, then it seems that before it gets a chance to call EndReceive, the callback gets generated again by more data arriving, and it throws everything into confusion. Anybody know how to fix this? Cheers, Andy
Maybe you can try using lock.
Advertisement
Wait until you are finished processing the current message before calling BeginReceive again.

Also, be aware that the threadpool used for managing async methods is limited. It might not handle large player counts.
AP: As my original post explains, it''s getting preempted before I can even call EndReceive, let alone call BeginReceive again.

This topic is closed to new replies.

Advertisement