0

created blank Console app:

namespace ClientUI
{
    class Program
    {
        static async void Main(string[] args)
        {
            await Task.Delay(1000);
        }
    }
}

The compiler throws:

Severity Code Description Project File Line Suppression State Error CS5001 Program does not contain a static 'Main' method suitable for an entry point

I read this article https://www.meziantou.net/2017/08/24/4-ways-to-enable-the-latest-c-features async Main is a C# 7.1 feature, ok, so I go to project properties >> Build >> Advanced and select Language version: C# 7.1

Trying to build again, but the error remains.

Cœur
  • 37,241
  • 25
  • 195
  • 267
monstro
  • 6,254
  • 10
  • 65
  • 111
  • Did you try having a non-namespaced `Main()` function? – Brian Kung Mar 19 '18 at 16:03
  • 1
    Main can not be *async* – Eser Mar 19 '18 at 16:04
  • 3
    @Eser it can be now : https://github.com/dotnet/csharplang/blob/c5fbcd6f4ecdd2cda0cf4403cc0a4090acfd279c/proposals/csharp-7.1/async-main.md – Ehsan Sajjad Mar 19 '18 at 16:04
  • 6
    Make it `static async Task`, not `async void`. – Evk Mar 19 '18 at 16:05
  • Evk, thanks, this whole async thing is so not natural :( so damn confusing – monstro Mar 19 '18 at 16:12
  • Note for that dupe marked by @Jerodev that the accepted answer is outdated. Relevant is https://stackoverflow.com/a/45908959/982149 – Fildor Mar 19 '18 at 16:31
  • 1
    @monstro what is really not natural is all that old `BeginDoThing`, `EndDoThing`, `DoThing().ContinueWith(x => DoOtherThing().ContinueWith(y => ...))))`. After a little bit practice you will be surprised how did you live without async before. It's implementation in C# is so good that many other languages (such as javascipt) copied it. – Evk Mar 19 '18 at 16:47
  • @Evk, sure, but I am not talking about old ways of doing this, it was nightmare, but this async-await pair that forces escalation of async all the way up the stack is confusing, maybe u'r right, I have to get used to it – monstro Mar 19 '18 at 16:49

0 Answers0