public void StartWatching() { DevicesAndPackets = new Dictionary <ICaptureDevice, ArrayList>(); DateTime DateToSavePcap = DateTime.Now.AddMinutes(MinToSaveSniff); while (keepRunning) { System.Threading.Thread.Sleep(1000); if (Devices == null) { Devices = CaptureDeviceList.Instance; foreach (ICaptureDevice Device in Devices) { StartDeviceSniff(Device); } } else { CaptureDeviceList NewDevices = CaptureDeviceList.Instance; foreach (ICaptureDevice NewDevice in NewDevices) { bool DeviceIsOld = false; foreach (ICaptureDevice OldDevice in Devices) { if (Devices.Contains(NewDevice)) { DeviceIsOld = true; break; } } if (!DeviceIsOld) { StartDeviceSniff(NewDevice); } } Devices = NewDevices; } if (DateTime.Now.CompareTo(DateToSavePcap) >= 0) { DateToSavePcap = DateToSavePcap.AddMinutes(MinToSaveSniff); SavePackets(); } } foreach (Thread CaptureThread in CaptureThreads) { CaptureThread.Abort(); } }