public void LoadingPackets(object a) { InfaDlyaLoadingPackets infa = (InfaDlyaLoadingPackets)a; List <Packet> packets2 = new List <Packet>(); while (true) { Packet packet; infa.communicator.ReceivePacket(out packet); if (packet == null) { break; } String[] row = new String[8]; row[0] = (packets2.Count + 1).ToString(); //Номер пакета row[1] = packet.Timestamp.Ticks.ToString(); //Время пакета в тактах row[2] = packet.Timestamp.ToString("yyyy-MM-dd HH:mm:ss,fff"); //Время пакета в общем формате row[3] = packet.Length.ToString(); //Размер пакета row[4] = packet.Ethernet.EtherType.ToString(); //Тип пакета switch (packet.Ethernet.EtherType) { case EthernetType.Arp: row[5] = packet.Ethernet.Arp.SenderProtocolIpV4Address.ToString(); row[6] = packet.Ethernet.Arp.TargetProtocolIpV4Address.ToString(); break; case EthernetType.IpV4: row[5] = packet.Ethernet.IpV4.Source.ToString(); row[6] = packet.Ethernet.IpV4.Destination.ToString(); break; case EthernetType.IpV6: row[5] = packet.Ethernet.IpV6.Source.ToString(); row[6] = packet.Ethernet.IpV6.CurrentDestination.ToString(); break; default: break; } dataGridView1.Invoke((Action)(() => { dataGridView1.Rows.Add(row); })); //Добавление строки в таблицу packets2.Add(packet); label1.Invoke((Action)(() => { label1.Text = "Загружено пакетов:" + packets2.Count; })); } packets = packets2; }
private void button1_Click(object sender, EventArgs e) { openFileDialog1.FileName = "C:\\Магистратура\\1 курс 2 семестр\\СОВвИ\\CTU-13-Dataset\\CTU-13-Dataset\\2 - взял"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { textBox1.Text = openFileDialog1.FileName; OfflinePacketDevice offlinePacketDevice = new OfflinePacketDevice(openFileDialog1.FileName); //offlinePacketDevice. PacketCommunicator communicator = offlinePacketDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000); // read timeout //communicator.ReceivePackets(0, DispatcherHandler); //List<Packet> packets = new List<Packet>(); InfaDlyaLoadingPackets infa = new InfaDlyaLoadingPackets(); infa.communicator = communicator; Task.Factory.StartNew(() => { LoadingPackets(infa); }); //Создание и запуск нового потока /* * while (true) * { * Packet packet; * communicator.ReceivePacket(out packet); * * if (packet == null) * { * break; * } * * packets.Add(packet); * textBoxLog.Text += packets.Count; * } */ } }