views:

88

answers:

1

Hello,

I am maintaining other's code and its using the class UdpClient. The code declares one instance of UdpClient and receives data continuously using the UdpClient.Receive().

When data is received, it is processed in another thread and the UdpClient calls Receive() again. At the same time when the data is processed the same client is sending a response back.

Question: Is this a bug? I think so because UdpClient is not thread safe so you can not call two methods at the same time. Anyways code is working fine but ...

+1  A: 

The fact that something isn't thread-safe doesn't mean you can't call two methods via different threads (or even one method via different threads), it just means that when the class was designed it wasn't designed with thread-safety at mind, thus the results of concurrent access are "unpredictable" from your POV.

This is not a bug. This is a mis-use.

M.A. Hanin
So that means that maybe everything works by luck or maybe everything works because the Receive and Send methods does not interfere each other, rigth?
SoMoS
Right, if you put God aside.
M.A. Hanin
Ok, I'm going to fix this mis-use. I don-not want to rely on God. Thanks :)
SoMoS