コード例 #1
0
        public AddNetworkInterfaceWindow(NetworkInterfaceToMonitor[] allNetworkInterfaces)
        {
            InitializeComponent();

            this.allNetworkInterfaces = allNetworkInterfaces;

            var nics = WsapmTools.GetAvailableNetworkInterfaces();

            foreach (var nic in nics)
            {
                this.comboBoxAvailableNetworkInterfaces.Items.Add(nic);
            }

            this.comboBoxAvailableNetworkInterfaces.Items.Add(WsapmTools.GetCommonDiaplayNameAllNetworkInterfaces());

            this.networkLoad      = new NetworkLoadCurrent();
            this.networkLoadTimer = null;
            this.networkLoadTimer = new Timer(OnShowNetworkLoadsCallback, null, new TimeSpan(), this.displayRefreshInterval);
        }
コード例 #2
0
        private void OnShowNetworkLoadsCallback(object state)
        {
            if (string.IsNullOrEmpty(this.currentSelectedNic))
            {
                return;
            }

            var  loadTotal    = string.Empty;
            var  loadSent     = string.Empty;
            var  loadReceived = string.Empty;
            bool allNics      = false;

            allNics = this.currentSelectedNic == WsapmTools.GetCommonDiaplayNameAllNetworkInterfaces();

            try
            {
                if (allNics)
                {
                    loadTotal    = WsapmConvert.ConvertByteToKBit(this.networkLoad.GetCurrentNetworkLoadTotalAllNics()).ToString("0.00") + " KBit/s";
                    loadSent     = WsapmConvert.ConvertByteToKBit(this.networkLoad.GetCurrentNetworkLoadUploadAllNics()).ToString("0.00") + " KBit/s";
                    loadReceived = WsapmConvert.ConvertByteToKBit(this.networkLoad.GetCurrentNetworkLoadDownloadAllNics()).ToString("0.00") + " KBit/s";
                }
                else
                {
                    loadTotal    = WsapmConvert.ConvertByteToKBit(this.networkLoad.GetCurrentNetworkLoadTotal(this.currentSelectedNic)).ToString("0.00") + " KBit/s";
                    loadSent     = WsapmConvert.ConvertByteToKBit(this.networkLoad.GetCurrentNetworkLoadUpload(this.currentSelectedNic)).ToString("0.00") + " KBit/s";
                    loadReceived = WsapmConvert.ConvertByteToKBit(this.networkLoad.GetCurrentNetworkLoadDownload(this.currentSelectedNic)).ToString("0.00") + " KBit/s";
                }
            }
            catch (Exception)
            {
            }

            Dispatcher.Invoke((Action)(() =>
            {
                this.labelCurrentNetworkLoadReceived.Content = loadReceived;
                this.labelCurrentNetworkLoadSent.Content = loadSent;
                this.labelCurrentNetworkLoadTotal.Content = loadTotal;
            }));
        }