我想从Background file transfer
运行Background audio agent
,但我在前台应用中运行正确的示例代码时出错。
以下是示例:
string transferFileName = @"http://www.reggaeavenue.com/MP3/leave%20short.mp3";
Uri transferUri = new Uri(Uri.EscapeUriString(transferFileName), UriKind.RelativeOrAbsolute);
BackgroundTransferRequest transferRequest = new BackgroundTransferRequest(transferUri);
transferRequest.Method = "GET";
string downloadFile = "result.mp3";
Uri downloadUri = new Uri("shared/transfers/" + downloadFile, UriKind.RelativeOrAbsolute);
transferRequest.DownloadLocation = downloadUri;
transferRequest.Tag = downloadFile;
transferRequest.TransferPreferences = TransferPreferences.AllowCellularAndBattery;
try
{
BackgroundTransferService.Add(transferRequest);
}
catch (InvalidOperationException ex)
{
MessageBox.Show("Unable to add background transfer request. " + ex.Message);
}
catch (Exception)
{
MessageBox.Show("Unable to add background transfer request.");
}
在将transferRequest添加到BackgroundTransferService的行上,我收到错误:
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at Microsoft.Phone.BackgroundTransfer.BackgroundTransferRequest.SubmitHelper()
at Microsoft.Phone.BackgroundTransfer.BackgroundTransferRequest.Submit()
at Microsoft.Phone.BackgroundTransfer.BackgroundTransferService.Add(BackgroundTransferRequest request)
at Project.AudioPlaybackAgent.AudioPlayer.CreateBackgroundTransfer()
那么可以从后台代理运行transferm吗?我怎样才能解决这个问题?感谢
答案 0 :(得分:2)
根据MSDN,后台代理不支持某些API(包括后台传输)。即使您设法做某些事情,您的应用也可能无法通过认证测试。
为什么不在主UI中下载文件或直接从Web源播放文件?