Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

AsyncRelayCommand IsRunning only true on return of Task

Abierto
#1,053 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
csharp
Área
tooling

Línea de trabajo

Comienza localizando la implementación de AsyncRelayCommand y sigue cómo se asignan ExecutionTask e IsRunning alrededor de la invocación del delegado asíncrono. Reproduce el problema con la parte síncrona de Execute y, a continuación, verifica que el estado del comando se actualiza antes de que se ejecute el cuerpo del delegado y permanece correcto durante la ejecución.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
C#
Estrellas
3.8k
Forks
401
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de CommunityToolkit/dotnet

Todos los issues de CommunityToolkit/dotnet

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.