public void Initialize() { Task.Factory.StartNew(() => { lock (_snifferLock) { if (_teraSniffer != null) { //dereference the existing sniffer if it exists var sniffer = _teraSniffer; _teraSniffer = null; sniffer.Enabled = false; sniffer.MessageReceived -= HandleMessageReceived; sniffer.NewConnection -= HandleNewConnection; Logger.Info("Sniffer has been disabled."); } IpSniffer ipSniffer = null; if (UseRawSockets) { ipSniffer = new IpSnifferRawSocketMultipleInterfaces(); } _teraSniffer = new TeraSniffer(ipSniffer, BasicTeraData.Servers); _teraSniffer.MessageReceived += HandleMessageReceived; _teraSniffer.NewConnection += HandleNewConnection; _teraSniffer.Enabled = true; Logger.Info("Sniffer has been enabled."); } }, TaskCreationOptions.LongRunning);//provide hint to start on new thread }
private void Form1_Load(object sender, EventArgs e) { _teraSniffer = new TeraSniffer(_basicTeraData.Servers); _teraSniffer.MessageReceived += teraSniffer_MessageReceived; _teraSniffer.NewConnection += _teraSniffer_NewConnection; _teraSniffer.Enabled = true; }
public void Initialize() { if (_teraSniffer != null) { //dereference the existing sniffer if it exists var sniffer = _teraSniffer; _teraSniffer = null; sniffer.Enabled = false; sniffer.MessageReceived -= HandleMessageReceived; sniffer.NewConnection -= HandleNewConnection; Logger.Info("Sniffer has been disabled."); } _teraSniffer = new TeraSniffer(BasicTeraData.Servers); _teraSniffer.MessageReceived += HandleMessageReceived; _teraSniffer.NewConnection += HandleNewConnection; _teraSniffer.Enabled = true; Logger.Info("Sniffer has been enabled."); }