[Window Store app]DownloadOperation,回调操作状态异常? 表象解决方案

邴兴为
2023-12-01

创建下载 :

download = downloader.CreateDownload(source, destinationFile);

Progress<DownloadOperation> progressCallback = new Progress<DownloadOperation>(DownloadProgress);

cts = new CancellationTokenSource();
download.StartAsync().AsTask(cts.Token, progressCallback);

  

正常回调:

private void DownloadProgress(DownloadOperation download)
{
    if (download.Progress.Status == BackgroundTransferStatus.Completed)
    {
        //operation
    }
}
  
download.Progress.Status ==    BackgroundTransferStatus.Completed 打断点 都是可以进入, 不打断电,下载后的操作就有异常,未找到原因,所以,偷鸡搞面延迟操作,解决了,不知道哪位能解释下问题何在?

ok 代码:
private void DownloadProgress(DownloadOperation download)
{
  ThreadPoolTimer.CreateTimer(async (timer) =>
  {
     if (download.Progress.Status ==    BackgroundTransferStatus.Completed)
   {
      await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
      {
        //operation
      });
     }
  }, TimeSpan.FromSeconds(1));
}

 

 

转载于:https://www.cnblogs.com/liumianweifeng/p/3374385.html

 类似资料: