Ejemplo n.º 1
0
        // 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();
                }
            }
        }