/// <summary> /// Initialize everything that needs to be initialized once we're logged in. /// </summary> /// <param name="login">The status of the login</param> /// <param name="message">Error message on failure, MOTD on success.</param> public void RegisterCommand(string name, Cogbot.Actions.Command live) { string orginalName = name; name = name.Replace(" ", "").ToLower(); while (name.EndsWith(".")) { name = name.Substring(0, name.Length - 1); } Monitor.Enter(Commands); live.TheBotClient = this; CommandInstance prev; if (!Commands.TryGetValue(name, out prev)) { CommandInstance command = new CommandInstance(live); Commands.Add(name, command); command.Name = orginalName; if (command.IsStateFul) { live.TheBotClient = this; command.WithBotClient = live; } } else { if (prev.CmdType != live.GetType()) { RegisterCommand("!" + orginalName, live); } } Monitor.Exit(Commands); }
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); } }
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); } }
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); }