use .Net UdpClient in a multithreaded environment

前端 未结 2 1070
一生所求
一生所求 2021-01-06 10:27

I have an instance of a class (lets call it A) which serves some threads, this instance only sends UDP packets via the UdpClient class. It initialize the the UdpClient in it

2条回答
  •  自闭症患者
    2021-01-06 11:02

    I think the best way here would be to create a new UdpClient every time the method is called. This way, you can be sure the code is safe. The performance isn't likely to be a problem, and if profiling shows that it is, only then you should start solving that.

    Also, you shouldn't forget to call EndSend() after each BeginSend() (ideally in the callback).

提交回复
热议问题