ConcurrentQueue<T>.TryDequeue(T) ConcurrentQueue<T>.TryDequeue(T) ConcurrentQueue<T>.TryDequeue(T) ConcurrentQueue<T>.TryDequeue(T) Method

Definição

Tenta remover e retornar o objeto no início da fila simultânea.Tries to remove and return the object at the beginning of the concurrent queue.

public:
 bool TryDequeue([Runtime::InteropServices::Out] T % result);
public bool TryDequeue (out T result);
member this.TryDequeue :  -> bool
Public Function TryDequeue (ByRef result As T) As Boolean

Parâmetros

result
T T T T

Quando este método retornar, se a operação tiver sido bem-sucedida, result conterá o objeto removido.When this method returns, if the operation was successful, result contains the object removed. Caso nenhum objeto esteja disponível para ser removido, o valor é não especificado.If no object was available to be removed, the value is unspecified.

Retornos

true se um elemento tiver sido removido e retornado do início do ConcurrentQueue<T> com êxito; caso contrário, false.true if an element was removed and returned from the beginning of the ConcurrentQueue<T> successfully; otherwise, false.

Comentários

ConcurrentQueue<T>manipula toda a sincronização internamente.ConcurrentQueue<T> handles all synchronization internally. Se dois threads TryDequeue chamarem precisamente no mesmo momento, nenhuma operação será bloqueada.If two threads call TryDequeue at precisely the same moment, neither operation is blocked. Quando um conflito é detectado entre dois threads, um thread precisa tentar recuperar o próximo elemento e a sincronização é manipulada internamente.When a conflict is detected between two threads, one thread has to try again to retrieve the next element, and the synchronization is handled internally.

TryDequeuetenta remover um elemento da fila.TryDequeue tries to remove an element from the queue. Se o método for bem-sucedido, o item será removido e o método retornará true; caso contrário, retornará false.If the method is successful, the item is removed and the method returns true; otherwise, it returns false. Isso acontece atomicamente em relação a outras operações na fila.That happens atomically with respect to other operations on the queue. Se a fila foi populada com um q.Enqueue("a"); q.Enqueue("b"); q.Enqueue("c"); código como e dois threads tentam, simultaneamente, remover a fila de um elemento, a um thread será removido da fila e bo outro thread será removido da fila.If the queue was populated with code such as q.Enqueue("a"); q.Enqueue("b"); q.Enqueue("c"); and two threads concurrently try to dequeue an element, one thread will dequeue a and the other thread will dequeue b. Ambas as chamadas TryDequeue para retornarão true, porque foram capazes de remover uma fila de um elemento.Both calls to TryDequeue will return true, because they were both able to dequeue an element. Se cada thread voltar a remover a fila de um elemento adicional, um dos threads será removido c da fila truee retornado, enquanto o outro thread encontrará a fila vazia e falseretornará.If each thread goes back to dequeue an additional element, one of the threads will dequeue c and return true, whereas the other thread will find the queue empty and will return false.

Aplica-se a

Veja também