我正在使用BackgroundUploadAsync
API 将文件上传到 OneDrive。大多数情况下,该函数工作正常,但有时调用会返回以下错误消息:
系统正忙于上一个后台上传...
我尝试关闭并重新启动应用程序,但仍然遇到相同的错误。
知道为什么会这样吗?如何重新初始化与 OneDrive 的连接?
这是执行上传的代码:
public static async Task<string> BackgroundUploadFile<T>(
string skydriveFolderId,
T objectToSerialize,
string fileNameInSkyDrive,
BackgroundTransferPreferences backgroundTransferPreferences =
BackgroundTransferPreferences.AllowCellularAndBattery)
{
string fileId = string.Empty;
try
{
var storageFolder = await GetSharedTransfersFolder();
StorageFile isolatedstorageFile = await storageFolder.CreateFileAsync(
fileNameInSkyDrive,
CreationCollisionOption.ReplaceExisting);
using (var writer = new StreamWriter
(await isolatedstorageFile.OpenStreamForWriteAsync()))
{
// convert to string
var _String = Serialize(objectToSerialize);
await writer.WriteAsync(_String);
}
Client.BackgroundTransferPreferences = backgroundTransferPreferences;
LiveOperationResult liveOpResult = await Client.BackgroundUploadAsync(
skydriveFolderId,
new Uri("/shared/transfers/" + fileNameInSkyDrive, UriKind.Relative),
OverwriteOption.Overwrite);
fileId = (string)liveOpResult.Result["id"];
Debug.WriteLine("BackgroundUploadFile: " + fileNameInSkyDrive);
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Upload Error", MessageBoxButton.OK);
Debug.WriteLine("\nError - BackgroundUploadFile: " + e.Message);
}
return fileId;
}
另外,我“怀疑” OneDrive 正在锁定帐户,因为有后台任务“卡住”并且 OneDrive 没有释放/释放它们?!