c# - 取消 Graph 方法 GetAsync(CancellationToken t) 似乎不起作用
问题描述
我似乎无法获得以下代码来取消GetAsync()
. 它继续获取文件。我设置了这种类似颜色的诊断程序,并且可以看到事情以应有的方式发生(单击事件引发取消,屏幕上其他地方的进度框架变为黄色、绿色和红色,它们应该发生)。
cts = new System.Threading.CancellationTokenSource(); //declared earlier...
var token = cts.Token;
BackgroundColor = Color.Red;
try
{
var fileContent = await
App.GraphClient.Me.Drive.Root.ItemWithPath(App.selectedOneDriveFolder + "/" + item.path).Content.Request().GetAsync(token);
// Do nothing with fileContent... this is just for testing
}
catch (Exception ex)
{
await DisplayAlert("Cancelled finally?", ex.Message, ":(");
}
BackgroundColor = Color.Green;
//and then the clicked event handler...
private void CancelDownloadButton_Clicked(object sender, EventArgs e)
{
cts?.Cancel();
ProgressFrame.BackgroundColor = Color.Yellow;
}
我还尝试了各种不同版本的运行(使用Task
、使用.Run
和/或.Wait(token)
),但无济于事。有任何想法吗?
解决方案
推荐阅读
- javascript - 如何在 php、html、脚本中创建具有 3 行和无限列的动态表?我还需要在每个字段中都有一个链接到网站的按钮
- parsing - 运算符和关键字应该放在词法分析器还是解析器中?
- reactjs - React 放置辅助函数的最佳实践
- android - 如何处理调试和生产 Android 应用程序的 MSAL 配置?
- azure - 如何在 Azure Devops 中为 Azure 创建服务连接(附图)
- r - R 中的 agnes() 如何处理因子列?
- javascript - 我的嵌套循环无法遍历对象数组
- android - 使用触摸事件进行自定义视图而不干扰用户的触摸事件
- python - 使用 Pandas 计算某些列/条目的统计信息?
- python - GEKKO 补料分批生物反应器的 ODE 方程组不可行系统