So I\'m writing a migration application, to take some data from our local storage and upload it to Amazon. Everything is working fine, except once I get into files that are
Is DisplayFileProgress thread-safe? I believe (looking at some older code) that the callback is called by each upload thread independently.
This code below is part of a small utility that we use to upload files ranging from 5 MB up to 1-2 GB or so. It's not remarkably different than yours, but perhaps it might help.
var writerlock = new object();
using (var tu = new TransferUtility(amazonS3Client, tuconfig))
{
var turequest = new TransferUtilityUploadRequest()
.WithBucketName(bucket)
.WithFilePath(file)
.WithKey(Path.GetFileName(file))
.WithStorageClass(S3StorageClass.ReducedRedundancy)
.WithPartSize(5 * 1024 * 1024)
.WithAutoCloseStream(true)
.WithCannedACL(S3CannedACL.PublicRead);
tuconfig.NumberOfUploadThreads = Environment.ProcessorCount - 1;
// show progress information if not running batch
if (interactive)
{
turequest.UploadProgressEvent += (s, e) =>
{
lock (writerlock)
{
... our progress routine ...
}
};
}
tu.Upload(turequest);
}