本文介绍了PasswordCredential获得BackgroundTransfer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林创建一个新的BackgroundTransfer并添加服务器证书:

Im creating a new BackgroundTransfer and adding Server Credentials:

PasswordCredential webdavLogin = new PasswordCredential();
webdavLogin.UserName = ServerSettings.Values["serverUsername"].ToString();
webdavLogin.Password = ServerSettings.Values["serverPassword"].ToString();
uploader.ServerCredential = webdavLogin;

现在的问题是,每次我运行BackgroundTransfer,以下异常引发:

Now the problem is, everytime i run the BackgroundTransfer, the following exception raises:

Exception from HRESULT: 0x80070565
The maximum number of secrets that may be stored in a single system has been exceeded

我搜索了CredentialStore,但它是空的,没有存储的凭据。我能做些什么?

I searched the CredentialStore, but it is empty, there are no Credentials stored.What can i do?

推荐答案

您只能有20名优秀的操作与凭证。

You can have only 20 outstanding operations with credentials.

如果你相信有一个当时运行未进行任何操作,则有可能是在缓存10遗忘或损坏操作。 AttachAsync()所有的人,并立即将其取消。

If you believed there are no operations running at the time, chances are there are 10 forgotten or broken operations in the cache. AttachAsync() all of them and cancel them immediately.

下面是一个例子:

private async Task CancelAll()
{
    // Get all running operations.
    var downloads = await BackgroundDownloader.GetCurrentDownloadsAsync();
    Debug.WriteLine(downloads.Count);

    var cancellationTokenSource = new CancellationTokenSource();
    List<Task> tasks = new List<Task>();
    foreach (var download in downloads)
    {
        var task = download.AttachAsync().AsTask(cancellationTokenSource.Token);
        tasks.Add(task);
    }

    try
    {
        // Cancel all the operations. It is expected they will throw exception.
        cancellationTokenSource.Cancel();
        Task.WaitAll(tasks.ToArray());
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex);
    }

    Debug.WriteLine("All canceled!");
}

然后,安排新的业务与 DownloadOperation.StartAsyn()

这篇关于PasswordCredential获得BackgroundTransfer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 12:55