Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UWP BackgroundDownloader即使在PC上也会冻结 stringurl=”http://any_urls"; MediaPlayer=新的MediaPlayer(); 公共主页() { 初始化组件(); Debug.WriteLine(“下载已启动”); var file=Download().Result;// 开始下载时忘记调用“AsTask”方法_C#_Download_Background_Uwp - Fatal编程技术网

C# UWP BackgroundDownloader即使在PC上也会冻结 stringurl=”http://any_urls"; MediaPlayer=新的MediaPlayer(); 公共主页() { 初始化组件(); Debug.WriteLine(“下载已启动”); var file=Download().Result;// 开始下载时忘记调用“AsTask”方法

C# UWP BackgroundDownloader即使在PC上也会冻结 stringurl=”http://any_urls"; MediaPlayer=新的MediaPlayer(); 公共主页() { 初始化组件(); Debug.WriteLine(“下载已启动”); var file=Download().Result;// 开始下载时忘记调用“AsTask”方法,c#,download,background,uwp,C#,Download,Background,Uwp,不能有异步构造函数 string url = "http://any_urls"; MediaPlayer player = new MediaPlayer(); public MainPage() { InitializeComponent(); Debug.WriteLine("Download started"); var file = Download().Result; // <-- Here's whe

不能有异步构造函数

string url = "http://any_urls";
    MediaPlayer player = new MediaPlayer();

    public MainPage()
    {
        InitializeComponent();

        Debug.WriteLine("Download started");
        var file = Download().Result; // <-- Here's where it stucks
        Debug.WriteLine("Download finished");

        player.Source = MediaSource.CreateFromStorageFile(file);
        player.Play();
    }

    private async Task<StorageFile> Download()
    {
        StorageFile destinationFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
            "data.mp3", CreationCollisionOption.GenerateUniqueName);
        BackgroundDownloader downloader = new BackgroundDownloader();
        DownloadOperation download = downloader.CreateDownload(new Uri(url), destinationFile);
        await download.StartAsync();
        return destinationFile;
    }
public主页()
{
this.InitializeComponent();
}
已加载专用异步无效页(对象发送方,RoutedEventArgs e)
{
Debug.WriteLine(“下载已启动”);
var file=await downloadsync();
Debug.WriteLine(“下载完成”);
player.Source=MediaSource.CreateFromStorageFile(文件);
player.Play();
}
私有异步任务下载异步()
{
StorageFile destinationFile=Wait ApplicationData.Current.LocalFolder.CreateFileAsync(
“data.mp3”,CreationCollisionOption.GenerateUniqueName);
BackgroundDownloader downloader=新的BackgroundDownloader();
DownloadOperation download=downloader.CreateDownload(新Uri(url),destinationFile);
等待下载.StartAsync().AsTask();
返回目标文件;
}
public MainPage()
{
    this.InitializeComponent();
}

private async void Page_Loaded(object sender, RoutedEventArgs e)
{
    Debug.WriteLine("Download started");
    var file = await DownloadAsync();
    Debug.WriteLine("Download finished");

    player.Source = MediaSource.CreateFromStorageFile(file);
    player.Play();
}

private async Task<StorageFile> DownloadAsync()
{
    StorageFile destinationFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
        "data.mp3", CreationCollisionOption.GenerateUniqueName);
    BackgroundDownloader downloader = new BackgroundDownloader();
    DownloadOperation download = downloader.CreateDownload(new Uri(url), destinationFile);
    await download.StartAsync().AsTask();
    return destinationFile;
}