Skip to content

Commit b811fe2

Browse files
authored
Document CS8892 warning (#20164)
* Document CS8892 warning * Update cs8892.md * Update cs8892.md * Update cs8892.md * Update toc.yml * Update cs8892.md * Update cs8892.md * Update cs8892.md * Update cs8892.md * Update cs8892.md * Update cs8892.md * Consistency
1 parent 5036292 commit b811fe2

File tree

2 files changed

+204
-137
lines changed

2 files changed

+204
-137
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: "Compiler warning (level 5) CS8892"
3+
ms.date: 08/26/2020
4+
f1_keywords:
5+
- "CS8892"
6+
helpviewer_keywords:
7+
- "CS8892"
8+
author: Youssef1313
9+
---
10+
11+
# Compiler warning (level 5) CS8892
12+
13+
Method 'method' will not be used as an entry point because a synchronous entry point 'method' was found.
14+
15+
This warning is generated on all async entry point candidates when you have multiple valid entry points, where they contain one or more synchronous entry point and one or more asynchronous entry points.
16+
17+
Because async main was only supported starting with C# 7.1, this warning isn't generated for projects targeting a previous version.
18+
19+
> [!NOTE]
20+
> The compiler always uses the synchronous entry point. In case there are multiple synchronous entry points, you get a compiler error.
21+
22+
## Example
23+
24+
The following examples generates CS8892:
25+
26+
```csharp
27+
using System;
28+
using System.Threading.Tasks;
29+
30+
public class Program
31+
{
32+
// CS8892: Method 'Program.Main()' will not be used as an entry point because a synchronous entry point 'Program.Main(string[])' was found.
33+
public static async Task Main()
34+
{
35+
await Task.Delay(1);
36+
}
37+
38+
public static void Main(string[] args)
39+
{
40+
Console.WriteLine(2);
41+
}
42+
}
43+
```
44+
45+
## How to fix this warning
46+
47+
Keep only the intended entry point for your program, and rename the others.
48+
49+
```csharp
50+
using System;
51+
using System.Threading.Tasks;
52+
53+
public class Program
54+
{
55+
public static async Task SomeOtherNameAsync()
56+
{
57+
await Task.Delay(1);
58+
}
59+
60+
public static void Main(string[] args)
61+
{
62+
Console.WriteLine(2);
63+
}
64+
}
65+
```

0 commit comments

Comments
 (0)