dotnet / dotnet/command-line-api
Problem running async Actions
- Lenguaje dominante
- C#
- Estrellas
- 3.7k
- Forks
- 428
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
While porting an existing project from the beta4 package in nuget to a more recent build (beta4.23181.5) I saw that async actions were not running to completion. After some debugging I found that if I made the action non-async, it would work as expected. I was able to reproduce it with the following.
```c#
using System;
using System.CommandLine;
using System.Threading.Tasks;
namespace CliAsyncTest;
public class Program
{
static async Task Main(string[] args)
{
var rootCmd = new CliRootCommand("CliAsyncTest - Test InvokeAsync()");
rootCmd.SetAction(async (_) => // Fix: remove async
{
Console.WriteLine("rootCmd Action starting");
await Task.Delay(100); // Fix: remove await, add .Wait()
Console.WriteLine("rootCmd Action complete");
});
return await rootCmd.Parse(args).InvokeAsync();
}
}
```
When I run this I will see the first line output to the console, but not the second. After applying the fixes in the comments I will see both lines output.
Tested with:
- beta4.23181.5
- Windows 10
Guía de contribución
Línea de trabajo
Comienza con la reproducción de C# proporcionada, centrándote en SetAction y en el punto de entrada Parse(args).InvokeAsync(). Ejecútala con la versión del paquete indicada y compara las acciones asíncronas y síncronas. Se considera terminado cuando la acción asíncrona imprime sus mensajes de inicio y finalización antes de que InvokeAsync retorne.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- csharp
- Área
- cli
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100