public CustomTransfer UpdateProcessListTransfers() { long totalDownloaded = 0; long totalUploaded = 0; lock (PIDUsageDictionary) { lock (MainWindowForm.ProcessDataSourceLocker) { foreach (Int32 PIDWithCurrentZeroTransferSpeed in ListOfPidTransfersToBeZeroed) { var processesDataToBeUpdated = ProcessDataSource.Where(processData => processData.PID == PIDWithCurrentZeroTransferSpeed); foreach (ProcessData processData in processesDataToBeUpdated) { processData.SetDownloadingTransfer(0); processData.SetUploadingTransfer(0); } } ListOfPidTransfersToBeZeroed.Clear(); foreach (KeyValuePair <Int32, CustomTransfer> PIDUsagePair in PIDUsageDictionary) { ProcessData processDataToBeUpdated = ProcessDataSource.FirstOrDefault( processData => (processData.isAlive || (Utils.ElapsedTime(processData.EndTime) < DeadPIDLookupTimer)) && processData.PID == PIDUsagePair.Key); if (!(processDataToBeUpdated is null)) { processDataToBeUpdated.AddReceivedSize(PIDUsagePair.Value.Received); processDataToBeUpdated.AddUploadSize(PIDUsagePair.Value.Sent); processDataToBeUpdated.SetDownloadingTransfer(Utils.CalculateSpeedPerSecond(PIDUsagePair.Value.Received, stopWatch.ElapsedMilliseconds)); processDataToBeUpdated.SetUploadingTransfer(Utils.CalculateSpeedPerSecond(PIDUsagePair.Value.Sent, stopWatch.ElapsedMilliseconds)); ListOfPidTransfersToBeZeroed.Add(PIDUsagePair.Key); }
private List <ProcessData> FindNewProcesses(Process[] processList) { List <ProcessData> processesToBeAdded = new List <ProcessData>(); foreach (Process process in processList) { ProcessData resProcess = ProcessDataSource.FirstOrDefault(processData => IsProcessEqualProcessData(process, processData)); if (resProcess == null) { processesToBeAdded.Add(new ProcessData(process)); } } return(processesToBeAdded); }