Amazon AWS SDK User's Guide Page 33: Callback with State Object

/ 155
Table of contents

Callback with Client

This example assumes that the following callback function has been defined.
public static void CallbackWithClient(IAsyncResult asyncResult)
{
try {
AmazonS3Client s3Client = (AmazonS3Client) asyncResult.AsyncState;
PutObjectResponse response = s3Client.EndPutObject(asyncResult);
Console.WriteLine("Finished PutObject operation with client callback");
}
catch (AmazonS3Exception s3Exception) {
//
// Code to process exception
//
}
}
The following line of code calls
BeginPutObject
and specifies the preceding callback function. When
the
PutObject
operation completes, the callback function is called. In this example, the call to
BeginPutObject
specifies the Amazon S3 client object for the
state
parameter.The callback function
uses the client to call the
EndPutObject
method to retrieve the server response. Because any exceptions
that occurred during the operation will be received when the callback calls
EndPutObject
, this call is
placed within a
try
block.
asyncResult = client.BeginPutObject(request, CallbackWithClient, client);

Callback with State Object

This example assumes that the following class and callback function have been defined.
class ClientState
{
AmazonS3Client client;
DateTime startTime;
public AmazonS3Client Client
{
get { return client; }
set { client = value; }
}
public DateTime Start
{
get { return startTime; }
set { startTime = value; }
}
}
public static void CallbackWithState(IAsyncResult asyncResult)
{
try {
ClientState state = asyncResult.AsyncState as ClientState;
AmazonS3Client s3Client = (AmazonS3Client)state.Client;
Version v2.0.0
29
AWS SDK for .NET Developer Guide
Asynchronous API for .NET 3.5

PDF file · ·

Print

Print document

Sharing

Questions about Amazon AWS SDK

No questions about this manual yet. Ask the first one.

Ask a question

We answer from the manual and name the page. The question appears on the site after it is checked.

All questions and answers ›

Related products and manuals for Software Amazon AWS SDK