private void Test(NicMonitor nic, string NicNames) { Thread receiveThread = new Thread(() => { nic.Update += (ss, ee) => { if (ee.Recv != 0 || ee.Sent != 0) { foreach (var list in _listNicMonitor) { if (!list.Equals(nic)) { list.Cancel(); } } Event(nic); _effective = nic; _listNicMonitor.Clear(); } }; nic.Start(NicNames); }); receiveThread.IsBackground = true; receiveThread.Start(); }
private void Event(NicMonitor nicMonitor) { nicMonitor.Error += (ss, ee) => { Error?.Invoke(ss, ee); }; nicMonitor.Stopped += (ss, ee) => { Stopped?.Invoke(ss, ee); }; nicMonitor.Update += (ss, ee) => { _network.Download = ee.Sent / 1024; _network.Upload = ee.Recv / 1024; Update?.Invoke(ss, ee); }; }
private void Start() { try { _nicNames = NicMonitor.GetNicNames().ToList(); if (_nicNames.Count > 0) { foreach (var list in _nicNames) { _listNicMonitor.Add(new NicMonitor()); } int i = 0; foreach (var list in _listNicMonitor) { Test(list, _nicNames[i++]); } } } catch { Error?.Invoke(this, EventArgs.Empty); } }