CloudQueue.BeginClear Method
From Storage Client Library NET API
Begins an asynchronous operation to clear all messages from the queue.
Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)
Usage
| Visual Basic |
|---|
Dim instance As CloudQueue Dim callback As AsyncCallback Dim state As Object Dim returnValue As IAsyncResult returnValue = instance.BeginClear(callback, state) |
Syntax
| Visual Basic |
|---|
Public Function BeginClear ( _ callback As AsyncCallback, _ state As Object _ ) As IAsyncResult |
| C# |
|---|
public IAsyncResult BeginClear ( AsyncCallback callback, Object state ) |
| C++ |
|---|
public: IAsyncResult^ BeginClear ( AsyncCallback^ callback, Object^ state ) |
| J# |
|---|
| JScript |
|---|
Parameters
- callback
Type: System.AsyncCallback
The callback delegate that will receive notification when the asynchronous operation completes.
- state
Type: System.Object
A user-defined object that will be passed to the callback delegate.
Return Value
Type: System.IAsyncResult
An IAsyncResult that references the asynchronous operation.
Example
The following code example illustrates using state when calling BeginClear.
| C# | |
|---|---|
using System;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
namespace QueueAsyncExample
{
public class QueueAsyncStateExample
{
public CloudQueue queueObject;
public object customStateInformation;
// Constructor for the example state class
public QueueAsyncStateExample( CloudQueue queue, object yourAdditionalStateObject )
{
this.queueObject = queue;
this.customStateInformation = yourAdditionalStateObject;
}
// Static call that starts clearing the queue
static void ClearQueueAsync( CloudQueue queue, object stateObject )
{
queue.BeginClear( QueueClearCallback,
new QueueAsyncStateExample( queue, stateObject ) );
}
// The callback method that is called once the clear operation is complete
static void QueueClearCallback( IAsyncResult opResult )
{
QueueAsyncStateExample state = (QueueAsyncStateExample) opResult.AsyncState;
CloudQueue queue = state.queueObject;
// End the BeginClear operation
queue.EndClear( opResult );
// ...other asynchronous operations could be started here if appropriate
}
}
}
| |
Remarks
The BeginClear method begins an operation to clear all messages from the queue.
If a queue contains a large number of messages, the operation may time out before all messages have been deleted. If the operation times out, the client should retry the operation until it succeeds, to ensure that all messages have been deleted.