我是新手,我正在开发后台传输功能来下载文件。它适用于Windows Phone 7.但问题是超过100 MB的文件无法使用“Transfer Preference = Allow Battery”下载,如果我使用“Transfer Preference = None”,则必须将手机连接到电源才能传输(任何文件大小)。到目前为止,这是我尝试过的,但它只适用于超过100MB的文件。任何帮助或建议都会很棒。谢谢!
private void downloadTrigger()
{
string transferFileName = urlTextBox.Text;
var transferUri = new Uri(Uri.EscapeUriString(transferFileName), UriKind.Absolute);
BackgroundTransferRequest transferRequest = new BackgroundTransferRequest(transferUri);
transferRequest.Method = "GET";
string downloadFile = transferFileName.Substring(transferFileName.LastIndexOf("/") + 1);
Uri downloadUri = new Uri("shared/transfers/" + downloadFile, UriKind.Relative);
transferRequest.DownloadLocation = downloadUri;
transferRequest.Tag = downloadFile;
if (transferRequest.TotalBytesToReceive >= 104857600)
{
try
{
transferRequest.TransferPreferences = TransferPreferences.None;
MessageBox.Show("For files over 100MB an external power is required to start copy.", "News box", MessageBoxButton.OK);
BackgroundTransferService.Add(transferRequest);
feedbackTextBlock.Text = "Queueing " + downloadFile;
return;
}
catch
{
}
}
try
{
transferRequest.TransferPreferences = TransferPreferences.AllowBattery;
BackgroundTransferService.Add(transferRequest);
feedbackTextBlock.Text = "Copying " + downloadFile;
}
catch
{
}
}