Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

AsyncRelayCommand IsRunning only true on return of Task

Aperta
#1,053 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
csharp
Ambito
tooling

Direzione di ricerca

Inizia individuando l'implementazione di AsyncRelayCommand e traccia come vengono assegnati ExecutionTask e IsRunning durante l'invocazione del delegato asincrono. Riproduci il problema con la parte sincrona di Execute, quindi verifica che lo stato del comando venga aggiornato prima dell'esecuzione del corpo del delegato e rimanga corretto durante l'esecuzione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
C#
Stelle
3.8k
Fork
401
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di CommunityToolkit/dotnet

Tutte le issue di CommunityToolkit/dotnet

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.