Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to use this library with async actions #10

Closed
ViRuSTriNiTy opened this issue May 2, 2022 · 8 comments · Fixed by #13
Closed

How to use this library with async actions #10

ViRuSTriNiTy opened this issue May 2, 2022 · 8 comments · Fixed by #13

Comments

@ViRuSTriNiTy
Copy link

ViRuSTriNiTy commented May 2, 2022

Hi there,

great package, it gets you started real quick. I try to use it with some simple async code and Serilog logging. But as soon as I have executed the first menu action the Serilog logging won't work anymore.

It seem like the use of GetAwaiter().GetResult() is causing this.

Do you have any hints / recommendation on how to use async code in the menu actions?

So lonG
Daniel

@lechu445
Copy link
Owner

lechu445 commented May 2, 2022

Hi @ViRuSTriNiTy,

Thanks for the compliment 😃

I try to use it with some simple async code and Serilog logging. But as soon as I have executed the first menu action the Serilog logging won't work anymore.

Could you please provide some code to reproduce the issue?

Do you have any hints / recommendation on how to use async code in the menu actions?

The menu does not support async code. My advice is to run the code synchronously by using .Result or GetAwaiter().GetResult().

@joymon
Copy link

joymon commented Jul 25, 2022

+1 to get async await implemented

@lechu445
Copy link
Owner

lechu445 commented Aug 6, 2022

@joymon could you provide me a use case where async await support is needed?

@joymon
Copy link

joymon commented Aug 10, 2022

Environent has a compilation setting "Treat warnings as errors" and when we use the below its showing a compilation error. "The async method lacks 'await' operators...."
async void TestMenu(string[] args)
{
var cm = new ConsoleMenu(args, level: 2);
cm.Show();
}
We can solve the compilation error using the below.
Task.Run(()=> cm.Show()).Wait();
It would be better if the library is natively async-await aware.

@lechu445
Copy link
Owner

It doesn't look like a real world use case.

In the provided example, the warning can be fixed simply by removing async keyword from method declaration

void TestMenu(string[] args)
{
  var cm = new ConsoleMenu(args, level: 2);
  cm.Show();
}

I asked about use case because console applications are, in fact, synchronous and async Main is just a syntax sugar of .GetAwaiter().GetResult(). See dotnet/csharplang#97 (comment)

@joymon
Copy link

joymon commented Sep 7, 2022

Thanks for the response. The sample was from an app having half a million lines of code. We will see if we can remove async.

lechu445 pushed a commit that referenced this issue Feb 17, 2023
resolves #10
lechu445 pushed a commit that referenced this issue Feb 17, 2023
resolves #10
@lechu445 lechu445 mentioned this issue Feb 17, 2023
@lechu445
Copy link
Owner

lechu445 commented Feb 17, 2023

I just released version 2.6.0 with the async API.
Happy coding!

@ViRuSTriNiTy
Copy link
Author

@lechu445 Works perfectly. Thank you!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants