Skip to content

async domain issue #531

Description

@galmok

I would like to work with dotnet async Main method, having the following signature:

static async Task Main(string[] args) {
        var parser = new Parser();
        var parserResult = parser.ParseArguments<Options>(args);
        var mainAsync = new MainAsync();
        parserResult.WithParsed<Options>(async options => await mainAsync.Run(options).ConfigureAwait());
}

Run is defined like:

    public async Task Run(Options options)
    {
        ...
    }

Problem is, my async methods behave strangely. They may work but can also simply terminate my program. It would seem I am doing something wrong, but I can't figure out what it is.

If I do this instead, there doesn't seem to be any problems, but I lose my async main method and some other stuff I have needs to be rewritten.

static void Main(string[] args) {
        var parser = new Parser();
        var parserResult = parser.ParseArguments<Options>(args);
        var mainAsync = new MainAsync();
        parserResult.WithParsed<Options>(options => mainAsync.Run(options).GetAwaiter().GetResult());
}

Why does the top-most Main fail in strange way and bottom one just works? Is CommandLineParser not async compatible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions