Пример #1
0
        private void CleanupThreadCallback(object state)
        {
            if (_disposed)
            {
                return;
            }

            if (Monitor.TryEnter(_timerLock) == false)
            {
                return;
            }

            try
            {
                lock (_syncRoot)
                {
                    // If we're below, or at, or minimum segment count threshold,
                    // there's no point in going any further.
                    if (_segments.Count <= _minimumSegmentCount)
                    {
                        return;
                    }

                    for (int i = _activeSegment; i > 0; i--)
                    {
                        ObjectPoolSegment <T> segment;
                        if (_segments.TryGetValue(i, out segment) == true)
                        {
                            // For the "old" segments that were allocated at startup, this will
                            // always be false, as their expiration dates are set at infinity.
                            if (segment.CanBeCleanedUp())
                            {
                                _segments.Remove(i);
                                segment.Dispose();
                            }
                        }
                    }
                }
            }
            finally
            {
                Monitor.Exit(_timerLock);
            }
        }
Пример #2
0
        internal void _listener_404(IHttpClientContext context, IHttpRequest request, IHttpResponse response)
        {
            HttpJob httpJob = new HttpJob(this, context, request, response);

            lock (HttpJobs)
            {
                HttpJobs.Add(httpJob);
            }
            // 5 second wait
            if (Monitor.TryEnter(HttpLock, waitForEachTime))
            {
                DoJob(httpJob);
                Monitor.Exit(HttpLock);
            }
            else
            {
                LogInfo("ERROR Waiting for prevoius request more than " +
                        TaskQueueHandler.GetTimeString(waitForEachTime));
                httpJob.OutOfLock = true;
                DoJob(httpJob);
            }
        }
 public void EnsureSimulator(Simulator simulator)
 {
     if (simulator == null || simulator.Handle == 0)
     {
         return;
     }
     if (!Monitor.TryEnter(_AllSimulators, 10000))
     {
         WriteLine("Cant lock _AllSimulators");
         return;
     }
     lock (SimMaster)
     {
         if (!SimMaster.ContainsKey(simulator.Handle))
         {
             SimMaster[simulator.Handle] = this;
             MasteringRegions.AddTo(simulator.Handle);
         }
     }
     try
     {
         {
             foreach (Simulator set in _AllSimulators)
             {
                 if (set.Handle == simulator.Handle && set.Client == simulator.Client)
                 {
                     return;
                 }
             }
             _AllSimulators.Add(simulator);
         }
         SimRegion.GetRegion(simulator);
     }
     finally
     {
         Monitor.Exit(_AllSimulators);
     }
 }
Пример #4
0
        private void InitializeFriendsList()
        {
            if (!Monitor.TryEnter(lockOneAtaTime))
            {
                return;
            }
            List <FriendInfo> friends = client.Friends.FriendList.FindAll((FriendInfo f) => true);

            friends.Sort((fi1, fi2) =>
            {
                if (fi1.IsOnline && !fi2.IsOnline)
                {
                    return(-1);
                }
                else if (!fi1.IsOnline && fi2.IsOnline)
                {
                    return(1);
                }
                else
                {
                    return(String.CompareOrdinal(fi1.Name, fi2.Name));
                }
            }
                         );

            listFriends.BeginUpdate();

            listFriends.Items.Clear();
            foreach (FriendInfo friend in friends)
            {
                listFriends.Items.Add(friend);
            }

            listFriends.EndUpdate();
            Monitor.Exit(lockOneAtaTime);
        }