コード例 #1
0
        // Internal Methods

        static void RecycleServicePoints()
        {
            lock (servicePoints) {
                var toRemove            = new ArrayList();
                var idleList            = new SortedDictionary <DateTime, ServicePoint> ();
                IDictionaryEnumerator e = servicePoints.GetEnumerator();
                while (e.MoveNext())
                {
                    ServicePoint sp = (ServicePoint)e.Value;
                    DateTime     idleSince;
                    if (sp.CheckAvailableForRecycling(out idleSince))
                    {
                        toRemove.Add(e.Key);
                        continue;
                    }

                    while (idleList.ContainsKey(idleSince))
                    {
                        idleSince = idleSince.AddMilliseconds(1);
                    }
                    idleList.Add(idleSince, sp);
                }

                for (int i = 0; i < toRemove.Count; i++)
                {
                    servicePoints.Remove(toRemove [i]);
                }

                if (maxServicePoints == 0 || servicePoints.Count <= maxServicePoints)
                {
                    return;
                }

                // get rid of the ones with the longest idle time
                foreach (var sp in idleList.Values)
                {
                    if (servicePoints.Count <= maxServicePoints)
                    {
                        break;
                    }
                    servicePoints.Remove(sp);
                }
            }
        }