/// <summary> /// Remove a Command from the queue /// </summary> public Command Dequeue(out InputState nState, out string nData) { lock (_lock) // Lock for thread safety { CmdQueueNode tempNode = null; if (_head != null) { tempNode = _head; _head = _head.Next; } if (tempNode != null) { nState = tempNode.State; nData = tempNode.Data; return(tempNode.Cmd); } else { nState = InputState.INVALID; nData = null; return(Command.None); } } }
// Check the length of the queue public int NumNodes() { int num = 0; CmdQueueNode tempNode = _head; while (tempNode != null) { num++; tempNode = tempNode.Next; } return(num); }
private object _lock = new object(); // Threadsafe lock object /// <summary> /// Add an Command to the queue /// </summary> public void Enqueue(Command nCmd, InputState nState, string nData = null) { lock (_lock) // Lock for thread safety { CmdQueueNode newNode = new CmdQueueNode(nCmd, nState, nData); if (_head == null) { _head = newNode; _tail = newNode; } else { _tail.Next = newNode; _tail = newNode; } } }
public void Dispose() { Cmd = null; Data = null; Next = null; }