UpoadOperationProgress返回的字节数已发送=立即发送的字节数

时间:2018-09-09 00:04:11

标签: c# uwp background-transfer

在成功完成上载操作后,我现在尝试获取一些进度UI。现在,这是我的代码,包括进度回调和该回调的处理程序。

public async Task<UploadOperation> BackgroundUploadVideoAsync(IStorageFile file, string gfyName)
{
    BackgroundUploader uploader = new BackgroundUploader();

    //… Create upload ...


    var partOperation = await uploader.CreateUploadAsync(new Uri("https://filedrop.gfycat.com/"), contentParts, "form-data", Guid.NewGuid().ToString() );
    var progress = new Progress<UploadOperation>(Shell.Current.HandleUpload);
    try
    {
        await partOperation.StartAsync().AsTask(progress);
        return partOperation;
        //var response = await operation.StartAsync().AsTask();
    }
    catch(Exception e)
    {

        var status = BackgroundTransferError.GetStatus(e.HResult);
        //await new MessageDialog($"An error occurred: {status}").ShowAsync();

    }
    return partOperation;
}

public async void HandleUpload(UploadOperation operation)
{
    await Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
    {
        var percent = operation.Progress.BytesSent / operation.Progress.TotalBytesToSend;
        progressBar.Value = Math.Truncate((double)percent);
        });
    }
}

问题是当调用HandleUpload时,'bytessent'和'bytestosend'立即相等,并且我的进度条设置为100%并在那里等待直到任务完成。我以前从未处理过进度回调,所以可能做错了。

0 个答案:

没有答案