Cătălin Rădoi
Cătălin Rădoi

Reputation: 1894

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?

Upvotes: 0

Views: 184

Answers (1)

tmaj
tmaj

Reputation: 35057

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.

Upvotes: 4

Related Questions