المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : "no overload for ... matches delegate..."



C# Programming
11-20-2009, 07:51 PM
Hello,

This is my first attempt at writing an event handler.

I am writing a simple packet capture utility utilizing a .NET interface to the WinPCap lib.

However, I've come across an error and do not know how to solve it.


private void button1_Click(object sender, EventArgs e)
{
/* Retrieve the device list */
List devices = Pcap.GetAllDevices();

//Extract a device from the list
PcapDevice device = devices[2];
//Register our handler function to the 'packet arrival' event
device.OnPacketArrival += new SharpPcap.Pcap.PacketArrivalEvent(device_PcapOnPacketArrival);
//Open the device for capturing
//true -- means promiscuous mode
//1000 -- means a read wait of 1000ms
device.Open(true, 1000);
Console.WriteLine("-- Listenning on {0}, hit 'Enter' to stop...",
device.Description);
//Start the capturing process
device.StartCapture();
//Wait for 'Enter' from the user.
Console.ReadLine();
//Stop the capturing process
device.StopCapture();
//Close the pcap device
device.Close();

}

private static void device_PcapOnPacketArrival(object sender, SharpPcap.Packets.Packet packet)
{
DateTime time = packet.PcapHeader.Date;
int len = packet.Header.Length;
Console.WriteLine("{0}:{1}:{2},{3} Len={4}",
time.Hour, time.Minute, time.Second, time.Millisecond, len);
}



new SharpPcap.Pcap.PacketArrivalEvent(device_PcapOnPacketArrival) throws an error:
"No overload for 'device_PcapOnPacketArrival' matches delegate 'SharpPcap.Pcap.PacketArrivalEvent'"

Here is some information that may prove useful:
"public delegate void PacketArrivalEvent(object sender, SharpPcap.PcapCaptureEventArgs e)
Member of SharpPcap.Pcap"


Also, I am referring to the outdate sample code located on the main site for the class wrapper (http://www.tamirgal.com/blog/Page/SharpPcap-tutorial-a-step-by-step-guide-to-using-SharpPcap.aspx).


How can I avoid this error? Any assistance is appreciated.


Thanks,

Matt