multiple file download using SkyDrive API

*爱你&永不变心* 提交于 2019-12-08 11:24:31

问题


I have the following code where I'm trying to download 3 different files from the users SkyDrive Account.

I'm using the SkyDrive API for Windows Phone development.

client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnDownloadCompletedVI);
client.DownloadAsync(fileIdVehicleItems);


client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnDownloadCompletedHI);
client.DownloadAsync(fileIdHistoryItems);


client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnDownloadCompletedRI);
client.DownloadAsync(fileIdRepairItems);

When I run this, the only method that gets called is the OnDownloadCompletedVI. All the files that are being downloaded are running through this method which is causing an error.

What am I doing incorrectly?

Update

I have the following method, but I have 2 other similar methods that do the exact same thing except it loads different objects (based off of the downloaded files).

The error I'm currently receiving:

An exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll but was not handled in user code

    void OnDownloadCompletedVI(object sender, LiveDownloadCompletedEventArgs e)
    {
        if (e.Result != null)
        {
            using (var stream_vi = e.Result)
            {
                StreamReader SRVI = new StreamReader(stream_vi);
                string contentVI = "";
                contentVI = SRVI.ReadToEnd();

                StringReader rdr_vi = new StringReader(contentVI);

                XmlSerializer serializer = new XmlSerializer(typeof(ObservableCollection<vehicle>));

                ObservableCollection<vehicle> importedVehicles = new ObservableCollection<vehicle>();
                importedVehicles = (ObservableCollection<vehicle>)serializer.Deserialize(rdr_vi);

                StorageHelper.Save<ObservableCollection<vehicle>>(App.vehicleData, importedVehicles);
            }
            //e.Result.Close();
        }
        else
        {
            infoTextBlock.Text = "Error downloading file: " + e.Error.ToString();
        }
    }

回答1:


Actually all three methods should be called. Of course, if the first method is called and throws an exception the other two won't trigger.

What you can do is either create a new client for each call, or download them in order, so when the OnDownloadCompletedVI method is complete, remove the event handler for OnDownloadCompletedVI and add the one for OnDownloadCompletedHI and then trigger the client.DownloadAsync(fileIdHistoryItems); at the end of the method.



来源:https://stackoverflow.com/questions/13336362/multiple-file-download-using-skydrive-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!