Why do these async calls terminate execution?
static void Main(string[] args)
{
var connectionstring = "esdb+discover://127.0.0.1:2113?tls=false";
var settings = EventStoreClientSettings.Create(connectionstring);
conn = new EventStoreClient(settings);
Parse();
}
static async void Parse()
{
var count = await GetEventCount("test@@test");
// can not reach here ... program ends exit code 0...
}
public static async Task<int> GetEventCount(string streamname)
{
var l = conn.ReadStreamAsync(Direction.Backwards, streamname, StreamPosition.Start);
var count = 0;
await foreach (var item in l)
{
count++;
}
return count;
}
You should
await
yourasync
method. See also https://learn.microsoft.com/en-us/archive/msdn-magazine/2013/march/async-await-best-practices-in-asynchronous-programming