我想从中运行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 吗?我怎样才能解决这个问题?谢谢