Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

AsyncRelayCommand IsRunning only true on return of Task

未关闭
#1,053 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
csharp
领域
tooling

调研方向

首先定位 AsyncRelayCommand 的实现,并跟踪在调用异步委托前后 ExecutionTask 和 IsRunning 的赋值方式。使用 Execute 的同步部分重现该问题,然后验证命令状态是否在委托体运行之前更新,并在执行期间保持正确。

由索引模型根据 Issue 内容生成。

描述

bug :bug:
Describe the bug

The ExecutionTask and IsRunning of the AsyncRelayCommand is only set after the execute returns a Task, so on the first real async function.
As long as it's running synchronously, the ExecutionTask is still the previous task and IsRunning is based on that one

Regression

No response

Steps to reproduce
  1. Create an AsyncRelayCommand with an async function that returns a Task
  relayCommand = AsyncRelayCommand(Execute);
  1. Check if is IsRunning in the synchronous part of the execution method
  async Task Execute()
  {
     Debug.Assert(relayCommand.IsRunnung); // Fails
     Debug.Assert(relayCommand.AsyncRelayCommand == null); // at least not be the previous task?
     await Task.Wait(1000);
  }
Expected behavior

That AsyncRelayCommand is set to null and IsRunning is true before the execute method is called.

Screenshots

No response

IDE and version

VS 2022

IDE version

No response

Nuget packages
  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)

8.2.0

Additional context

Ideally, you'd not call the IsRunning inside the Execute call, but I've done it by accident already that I run setup that I wanted to skip when a command is running, that is called from the Execute function before any network calls.

Workaround is just doing

await Task.Yield();

as the first line in the Execute method.

Help us help you

Yes, I'd like to be assigned to work on this item

主要语言
C#
星标
3.8k
派生
401
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

CommunityToolkit/dotnet 的其他 Issue

查看 CommunityToolkit/dotnet 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。