public static DateTime addMonitored(Monitored mm) { DateTime key = DateTime.Now; lock (List) { while (true) { try { List.Add(key, mm); mm.Started = key; if (Display != null) { try { Display.RebuildGui(); // thread safe method, can call here } catch { } } break; } catch { key = key.AddTicks(-1); } } } return(key); }
// Use this for initialization void Start() { targetPower = startingTargetPower; scoreQueue = new Queue <MoraleChangeMessage> (); totalScore = new Monitored <float>(0); Dispatcher <MoraleChangeMessage> .Subscribe(AddMessageToQueue); }
public override int GetHashCode() { unchecked { var hashCode = AgentID; hashCode = (hashCode * 397) ^ (MachineID != null ? MachineID.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (DeviceGuid != null ? DeviceGuid.GetHashCode() : 0); hashCode = (hashCode * 397) ^ CustomerID; hashCode = (hashCode * 397) ^ (CustomerName != null ? CustomerName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ FolderID.GetHashCode(); hashCode = (hashCode * 397) ^ (AgentName != null ? AgentName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (SystemName != null ? SystemName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (MachineName != null ? MachineName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (DomainName != null ? DomainName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (CurrentLoggedUsers != null ? CurrentLoggedUsers.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ComputerDescription != null ? ComputerDescription.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Monitored.GetHashCode(); hashCode = (hashCode * 397) ^ LastPatchManagementReceived.GetHashCode(); hashCode = (hashCode * 397) ^ (AgentVersion != null ? AgentVersion.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Favorite.GetHashCode(); hashCode = (hashCode * 397) ^ ThresholdID.GetHashCode(); hashCode = (hashCode * 397) ^ MonitoredAgentID.GetHashCode(); hashCode = (hashCode * 397) ^ Created.GetHashCode(); hashCode = (hashCode * 397) ^ Modified.GetHashCode(); hashCode = (hashCode * 397) ^ Online.GetHashCode(); hashCode = (hashCode * 397) ^ (ReportedFromIP != null ? ReportedFromIP.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (AppViewUrl != null ? AppViewUrl.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Motherboard != null ? Motherboard.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Processor != null ? Processor.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Memory.GetHashCode(); hashCode = (hashCode * 397) ^ (Display != null ? Display.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Sound != null ? Sound.GetHashCode() : 0); hashCode = (hashCode * 397) ^ ProcessorCoresCount.GetHashCode(); hashCode = (hashCode * 397) ^ (SystemDrive != null ? SystemDrive.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ProcessorClock != null ? ProcessorClock.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Vendor != null ? Vendor.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (VendorSerialNumber != null ? VendorSerialNumber.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (VendorBrandModel != null ? VendorBrandModel.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ProductName != null ? ProductName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (OS != null ? OS.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (OSType != null ? OSType.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (OSVersion != null ? OSVersion.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (OSBuild != null ? OSBuild.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (WindowsSerialNumber != null ? WindowsSerialNumber.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Office != null ? Office.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (OfficeSP != null ? OfficeSP.GetHashCode() : 0); hashCode = (hashCode * 397) ^ OfficeOEM.GetHashCode(); hashCode = (hashCode * 397) ^ (OfficeSerialNumber != null ? OfficeSerialNumber.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (OfficeFullVersion != null ? OfficeFullVersion.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (LastLoginUser != null ? LastLoginUser.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (HardwareDisks?.Sum(x => x.GetHashCode()) ?? 0); hashCode = (hashCode * 397) ^ (MacAddresses?.Sum(x => x.GetHashCode()) ?? 0); hashCode = (hashCode * 397) ^ (IpAddresses?.Sum(x => x.GetHashCode()) ?? 0); return(hashCode); } }
public static int CountActive() { int ret = 0; for (int i = 0; i < List.Count; i++) { Monitored mm = (Monitored)List.GetByIndex(i); if (!mm.Complete) { ret++; } } return(ret); }
public static void markComplete(Monitored mm, bool success, string comment) { if (mm != null) { mm.Complete = true; mm.Finished = DateTime.Now; mm.Success = success; if (comment != null) { mm.Comment = comment + " " + mm.Comment; } WorkValues(); // make sure values are updated on display } }
// Use this for initialization void Start() { if (_all != null) { _all.Add(this); } state = new Monitored <TurbineState> (null); state.OnValueChanged += GetComponent <TurbineParticle> ().OnStateChange; windDirection = windVelocity.value.normalized; transform.forward = windDirection; windVelocity.OnValueChanged += OnWindVelocityChanged; UpdateEfficiency(); FindObjectOfType <Fossil_Fuel_Particle>().UpdateParticles(); }
// called 3 times per second; can throw exceptions: public static void purge() { int minValue = 100; bool hasFailed = false; int secsToHold = 30; if (List.Count > 20) { secsToHold = 0; // with way too many monitors in effect, holding complete ones is too expensive } else if (List.Count > 10) { secsToHold = 2; // with many monitors in effect, holding complete ones for long time is too expensive } lock (List) { // purge the list - remove old completed entries for (int i = List.Count - 1; i >= 0; i--) { Monitored mm = (Monitored)List.GetByIndex(i); if (mm.Complete && (secsToHold == 0 || mm.Finished.AddSeconds(secsToHold).CompareTo(DateTime.Now) < 0)) { List.Remove(mm.Started); //.RemoveAt(i); mm.Purged = true; continue; } else if (!mm.Complete && mm.Progress > 0 && mm.Progress < minValue) { minValue = mm.Progress; } if (mm.Complete && !mm.Success) { hasFailed = true; } } } if (Display != null) { Display.purge(); // thread safe method, can call here if (doWorkValues || ++count > 10) // force periodic update, avoid stale values { doWorkValues = false; Display.WorkValues(); // thread safe method, can call here if (count > 10) { count = 0; } } Display.MayRefresh(); // thread safe method, can call here } if (Indicator != null) { int countActive = CountActive(); if (countActive > 0) { Indicator.BackColor = hasFailed ? Color.Red : Color.Green; if (minValue > 0 && minValue < 100) { Indicator.Text = "" + minValue + "%"; LibSys.StatusBar.Progress(minValue); } else if (countActive > 0) { Indicator.Text = "" + countActive + "+" + ThreadPool2.WaitingCallbacks; //Project.threadPool.RequestQueueCount; LibSys.StatusBar.ProgressOff(); } } else { Indicator.BackColor = Color.LightGray; Indicator.Text = ""; LibSys.StatusBar.ProgressOff(); } } }
// must be called from this form's thread - actually is called from the constructor and from Paint() private void RebuildProgressBars() { inRebuild = true; this.SuspendLayout(); try { int i; for (i = 0; i < List.Count; i++) { DisplayElement de = (DisplayElement)List.GetByIndex(i); this.Controls.Remove(de.progressBar); this.Controls.Remove(de.label); } List.Clear(); int yPos = 48; int activeCount = 0; for (i = 0; i < ProgressMonitor.List.Count && yPos < 1000; i++) { DateTime key = (DateTime)ProgressMonitor.List.GetKey(i); Monitored mm = (Monitored)ProgressMonitor.List.GetByIndex(i); DisplayElement de = new DisplayElement(); de.monitored = mm; if (!mm.Complete) { activeCount++; } // // progressBar // de.progressBar.Location = new System.Drawing.Point(16, yPos); de.progressBar.Name = "progressBar" + i; de.progressBar.Size = new System.Drawing.Size(120, 16); de.progressBar.TabIndex = 1; // // progressLabel // de.label.Location = new System.Drawing.Point(152, yPos); de.label.Name = "progressLabel" + i; de.label.Size = new System.Drawing.Size(800, 16); de.label.TabIndex = 2; List.Add(key, de); this.Controls.Add(de.progressBar); this.Controls.Add(de.label); yPos += 24; } int newHeight = yPos + 20; // do not allow it to resize too often, just when it grows or shrinks fast. if (ProgressMonitor.List.Count == 0 || newHeight > this.ClientSize.Height || newHeight < this.ClientSize.Height - 120) { int width = this.ClientSize.Width; this.ClientSize = new System.Drawing.Size(width, newHeight); } headLabel.Text = "Download Tasks - total:" + i + " active: " + activeCount + " threads: " + ThreadPool2.ActiveThreads //Project.threadPool.CurrentThreadCount + " queue: " + ThreadPool2.WaitingCallbacks; //Project.threadPool.RequestQueueCount; _WorkValues(); // set all current values } catch {} finally { this.ResumeLayout(false); inRebuild = false; } }