2014-01-29 74 views
0

我試圖在UploadAsync完成後將一些數據傳遞給continuation方法。我可以通過使用該方法讀取AsyncState,但我不知道如何從外部設置它?Google雲端存儲.Net API:使用UploadAsync設置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(); 

感謝。

回答

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? 
});