public void Run() { TrafficMonitorTask = new TrafficMonitor(MainWindowFormCallback, ProcessDataSource, CancellationTokenTask, ListRefreshRate); TrafficMonitorTask.StartMonitoringInternetTrafficAsync(); while (!CancellationTokenTask.IsCancellationRequested) { Stopwatch startStopwatch = Stopwatch.StartNew(); try { List <ProcessData> newProcesses = GetNewProcesses(); CustomTransfer TotalTransferSize = TrafficMonitorTask.UpdateProcessListTransfers(); InvokeUpdateUI(newProcesses, TotalTransferSize); } catch (Exception e) { Debug.WriteLine($"Received exception on monitor thread: {e.Message}"); if (!(MainWindowForm.ErrorLogger is null)) { MainWindowForm.ErrorLogger.LogObject(Utils.GetCallerClassFuncName(), 10, "Failed to refresh process list", e); } } SleepDelay(startStopwatch); } }
private void InvokeUpdateUI(List <ProcessData> newProcesses, CustomTransfer totalTransferSize) { UIUpdateInvokeStatus = MainWindowFormCallback.BeginInvoke((MethodInvoker) delegate { DataGridViewWithProcessDataListSource dataGridView = MainWindowFormCallback.GetProcessGridView(); dataGridView.SaveAndSuspendCurrentView(); AddNewProcesses(newProcesses); MainWindowFormCallback.UpdateVisibilityOfDeadProcessesInDataGridView(false); UpdateSortedDataInDataGridView(shouldMarkDeadProcesses: true); dataGridView.RestoreAndResumeCurrentView(); dataGridView.Refresh(); UpdateBottomToolStrip(totalTransferSize); }); }
private static void SafeAddNetworkData(Dictionary <int, CustomTransfer> PIDUsageDictionary, Int32 PID, Int32 Rcvd, Int64 Sent) { lock (PIDUsageDictionary) { if (PIDUsageDictionary.ContainsKey(PID)) { PIDUsageDictionary[PID].Received += Rcvd; PIDUsageDictionary[PID].Sent += Sent; } else { PIDUsageDictionary[PID] = new CustomTransfer { Received = Rcvd, Sent = Sent }; } } }
private void UpdateBottomToolStrip(CustomTransfer totalTransferSize) { MainWindowFormCallback.UpdateNoOfShowedProcessesInTable(); MainWindowFormCallback.AddTotalDownloadUpload(totalTransferSize.Received, totalTransferSize.Sent); }