User guide
Table Of Contents
- AWS SDK for .NET
- Table of Contents
- AWS SDK for .NET Developer Guide
- Getting Started with the AWS SDK for .NET
- Programming with the AWS SDK for .NET
- AWS SDK for .NET Tutorials and Examples
- Managing ASP.NET Session State with Amazon DynamoDB
- Tutorial: Creating Amazon EC2 Instances with the AWS SDK for .NET
- Tutorial: Grant Access Using an IAM Role and the AWS SDK for .NET
- Tutorial: Amazon EC2 Spot Instances
- Creating and Using an Amazon SQS Queue with the AWS SDK for .NET
- Creating an Amazon Route 53 Hosted Zone and Adding Resource Record Sets
- Additional Resources
- Document History

}
}
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 Begin-
PutObject 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;
PutObjectResponse response = state.Client.EndPutObject(asyncResult);
Console.WriteLine("Finished PutObject. Elapsed time: {0}",
(DateTime.Now - state.Start).ToString());
}
catch (AmazonS3Exception s3Exception) {
//
// Code to process exception
//
}
}
The following line of code calls BeginPutObject and specifies the above callback function. When the
PutObject operation completes, the callback function is called. In this example, the call to BeginPutO-
bject specifies, for the state parameter, an instance of the ClientState class defined previously.
This class embeds the Amazon S3 client as well as the time at which BeginPutObject is called.The
Version v2.0.0
20
AWS SDK for .NET Developer Guide
Asynchronous API for .NET 3.5