我通过这种方法异步上传文件到服务器:
public static void uploadFile(String filePath)
{
///.. some code here
System.Threading.Tasks.Task<Google.Apis.Upload.IUploadProgress> task = insertRequest.UploadAsync();
task.ContinueWith(t =>
{
//.. t.Result.BytesSent(); returns number of bytes sent to the server
uploadStream.Dispose();
});
timer1.Start();
}
我需要知道发送到服务器的字节数:
t.Result.BytesSent();
但是我想在timer_Tick事件中每秒调用一次这个方法,我该怎么办?如何从不同的任务调用此方法?
private void timer1_Tick(object sender, EventArgs e)
{
//
}