CloudBlob.BeginFetchAttributes Method (AsyncCallback, Object)

Storage Client Library NET API

[This topic is part of the Microsoft Azure Storage Client Library 1.7, which has been deprecated. See Storage Client Library for the latest version.]

Begins an asynchronous operation to populate the blob's properties and metadata.

Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)

Usage

Visual Basic
Dim instance As CloudBlob
Dim callback As AsyncCallback
Dim state As Object
Dim returnValue As IAsyncResult

returnValue = instance.BeginFetchAttributes(callback, state)

Syntax

Visual Basic
Public Function BeginFetchAttributes ( _
	callback As AsyncCallback, _
	state As Object _
) As IAsyncResult
C#
public IAsyncResult BeginFetchAttributes (
	AsyncCallback callback,
	Object state
)
C++
public:
IAsyncResult^ BeginFetchAttributes (
	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 creates an instance of a blob in the cloud, and populates it with metadata. It then creates a second blob that references the same blob instance, and populates it’s properties and metatdata using an asynchronous call.

C# Copy Code
private void Eg_AsyncListBlobPropertiesAndMetadata2(Uri blobEndpoint, string accountName, string accountKey)
{
    // Create a service client for credentialed access to the Blob service.
    CloudBlobClient blobClient =
        new CloudBlobClient(blobEndpoint,
            new StorageCredentialsAccountAndKey(accountName, accountKey));

    // Create a blob reference.
    CloudBlob myBlob = blobClient.GetBlobReference("mycontainer/myblob.txt");

    // Write text to the blob.
    myBlob.UploadText("One man that has a mind and knows it can always beat ten men who haven't and don't.");

    // Define metadata for the blob.
    myBlob.Metadata["category"] = "quotes";
    myBlob.Metadata["owner"] = "George Bernard Shaw";

    // Update the blob instance with the new metadata.
    myBlob.SetMetadata();

    // Create a second blob reference, that references the same blob instance.
    CloudBlob myBlob2 = blobClient.GetBlobReference("mycontainer/myblob.txt");

    // At this point, myBlob2 has neither system properties nor metadata.
    // Populate the blob's attributes.
    // Use aResult to determine when this asynchronous call has completed.
    IAsyncResult aResult = myBlob2.BeginFetchAttributes(Eg_BeginFetchAttributesCallback, myBlob2);

    // The properties and metatdata won't appear on the blob 
    // until the asynchronous call has completed.
    while (!aResult.IsCompleted)
    {
        // The calling thread can perfrom other work while the asynchronous call completes.
        Thread.Sleep(100);
    }

    // Verify that myBlob2's properties and metadata have in fact been populated.
    Console.WriteLine("Blob:\t" + myBlob2.Attributes.Uri);
    Console.WriteLine();

    Console.WriteLine("Blob properties:");
    Console.WriteLine("BlobType:\t\t" + myBlob2.Attributes.Properties.BlobType);
    Console.WriteLine("LastModifiedUTC:\t" + myBlob2.Attributes.Properties.LastModifiedUtc);
    Console.WriteLine("ETag:\t" + myBlob2.Attributes.Properties.ETag);
    Console.WriteLine();

    //Enumerate the blob's metadata.
    foreach (var metadataKey in myBlob2.Metadata.Keys)
    {
        Console.WriteLine("Metadata name:\t" + metadataKey.ToString());
        Console.WriteLine("Metadata value:\t" + myBlob2.Metadata.Get(metadataKey.ToString()));
    }
}

private void Eg_BeginFetchAttributesCallback(IAsyncResult result)
{
    CloudBlob blobForAttributes = (CloudBlob)result.AsyncState;
    blobForAttributes.EndFetchAttributes(result);
}

Remarks

The BeginFetchAttributes method begins an operation to populate the blob's system properties and user-defined metadata. Before reading a blob's properties or metadata, you should always call this method or the FetchAttributes method to retrieve the latest values for the blob's properties and metadata from the service.


Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows Vista, Windows 7, Windows Server 2008, Windows 8.1, Windows Server 2012 R2, Windows 8 and Windows Server 2012

Change History

See Also