2

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 ...

4

1 に答える 1

3

何かがスレッドセーフではないという事実は、異なるスレッドを介して 2 つのメソッド (または異なるスレッドを介して 1 つのメソッドでさえも) を呼び出すことができないという意味ではなく、クラスが設計されたときにスレッドで設計されていなかったことを意味します。 -安全性を念頭に置いているため、同時アクセスの結果はPOVからは「予測できません」。

これはバグではありません。これは誤用です。

于 2010-04-22T10:23:26.530 に答える