Browse Source

docs: use async main

* Removed text async

* Updated code

* Added main as proxy task
tags/3.0.0
Hitmasu GitHub 4 years ago
parent
commit
125f6c7862
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 12 deletions
  1. +2
    -6
      docs/guides/getting_started/first-bot.md
  2. +1
    -2
      docs/guides/getting_started/samples/first-bot/async-context.cs
  3. +1
    -2
      docs/guides/getting_started/samples/first-bot/complete.cs
  4. +2
    -2
      docs/guides/getting_started/samples/first-bot/structure.cs

+ 2
- 6
docs/guides/getting_started/first-bot.md View File

@@ -80,15 +80,11 @@ recommended for these operations to be awaited in a
properly established async context whenever possible. properly established async context whenever possible.


To establish an async context, we will be creating an async main method To establish an async context, we will be creating an async main method
in your console application, and rewriting the static main method to
invoke the new async main.
in your console application.


[!code-csharp[Async Context](samples/first-bot/async-context.cs)] [!code-csharp[Async Context](samples/first-bot/async-context.cs)]


As a result of this, your program will now start and immediately
jump into an async context. This allows us to create a connection
to Discord later on without having to worry about setting up the
correct async implementation.
As a result of this, your program will now start into an async context.


> [!WARNING] > [!WARNING]
> If your application throws any exceptions within an async context, > If your application throws any exceptions within an async context,


+ 1
- 2
docs/guides/getting_started/samples/first-bot/async-context.cs View File

@@ -1,7 +1,6 @@
public class Program public class Program
{ {
public static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
public static Task Main(string[] args) => new Program().MainAsync();


public async Task MainAsync() public async Task MainAsync()
{ {


+ 1
- 2
docs/guides/getting_started/samples/first-bot/complete.cs View File

@@ -2,8 +2,7 @@ public class Program
{ {
private DiscordSocketClient _client; private DiscordSocketClient _client;
public static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
public static Task Main(string[] args) => new Program().MainAsync();


public async Task MainAsync() public async Task MainAsync()
{ {


+ 2
- 2
docs/guides/getting_started/samples/first-bot/structure.cs View File

@@ -10,11 +10,11 @@ using Discord.WebSocket;
class Program class Program
{ {
// Program entry point // Program entry point
static void Main(string[] args)
static Task Main(string[] args)
{ {
// Call the Program constructor, followed by the // Call the Program constructor, followed by the
// MainAsync method and wait until it finishes (which should be never). // MainAsync method and wait until it finishes (which should be never).
new Program().MainAsync().GetAwaiter().GetResult();
return new Program().MainAsync();
} }


private readonly DiscordSocketClient _client; private readonly DiscordSocketClient _client;


Loading…
Cancel
Save