Google云端存储.Net API:使用UploadAsync设置AsyncState

时间:2014-01-29 21:20:13

标签: google-cloud-storage google-api-dotnet-client

一旦UploadAsync完成,我试图将一些数据传递给continuation方法。我可以使用该方法读取AsyncState,但我不知道如何从外部设置它?

以下是我目前的样本:

Action<Task<IUploadProgress>> myAction = (input) => 
{
  object asyncState = input.AsyncState;
  IUploadProgress result = input.Result;
};

Task<IUploadProgress> uploadTask = service.Objects.Insert(myObject, bucketName, stream, "").UploadAsync();

uploadTask.ContinueWith(myAction);

uploadTask.Wait();

感谢。

1 个答案:

答案 0 :(得分:0)

我会做以下事情:

var insertMediaReq = service.Objects.Insert(myObject, bucketName, stream, "");
Task<IUploadProgress> uploadTask = insertMediaReq.UploadAsync();
uploadTask.ContinueWith(t => 
{
  // Here you can use t.Result. 
  // But I don't get it. what are you trying to do here?
});