我尝试使用以下代码下载文件:
private async void Button_Click(object sender, RoutedEventArgs e)
{
try
{
Uri source;
Uri.TryCreate(txbUri.Text.Trim(),UriKind.Absolute, out source);
StorageFile destfile = await x.CreateFileAsync(Path.GetFileName(source.LocalPath), CreationCollisionOption.GenerateUniqueName);
BackgroundDownloader downloader = new BackgroundDownloader();
DownloadOperation download = await Task.Run(() => { return downloader.CreateDownload(source, destfile); });
await HandleDownloadAsync(download, true);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
但该行有例外:
downloader.CreateDownload(source, destfile);
例外是:
班级未注册
我使用确切的代码编译了Microsoft示例,它运行正常。但我不知道为什么我的应用程序没有。