'If I am not awaiting a Call, does it still execute?

ok so I have a function

public async Task Foo(){
    await SomeOtherFunctionAsync();
    Bar();
}

Bar() can't be made async, it only removes an entry from a dictionary.

What is the best approach in this case?

  • is the Bar() executed still if it is not awaited?
  • should I use Task.FromResult or something like that?


Solution 1:[1]

One great thing about programming is that it very often is very easy to try.

await Foo();

async Task Foo(){
    await SomeOtherFunctionAsync();
    Bar();
}

async Task SomeOtherFunctionAsync() {
    await Task.Delay(TimeSpan.FromMilliseconds(100));
}

void Bar() {
    Console.WriteLine("Hello from Bar");
}

This prints Hello from Bar which shows Bar() is called.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tymtam