如果我使用多个线程,我应该在发送数据包时锁定我的机器适配器吗?

时间:2015-02-03 16:48:56

标签: c# multithreading packets pcap.net

我正在使用Pcap.Net通过我的机器适配器传输数据包,在某些情况下,我使用Parallel.ForEach MaxDegreeOfParallelism同时读取来自多个文件的数据包,其中// Open the my device using (PacketCommunicator communicator = selectedDevice.Open(100, PacketDeviceOpenAttributes.Promiscuous, 1000)) { Packet packet; // Read packet from file while (inputCommunicator.ReceivePacket(out packet) == PacketCommunicatorReceiveResult.Ok) { // Send packet communicator.SendPacket(packet); } } 属性可以更改。 所以我想知道我是否需要锁定发送此数据包的对象..

这是我的主要发送数据包的方式:

{{1}}

1 个答案:

答案 0 :(得分:0)

根据我对WinPcap的理解,我相信如果你不同时在两个线程中使用相同的PacketCommunicator,你应该没问题。