To provide some more C# specific context around writing a good message event handler:
In the HandleMessageEvent callback, just write the message to some kind of collection. I strongly recommend a System.Threading.Channel
, using the CreateUnbounded
factory. Then have a separate task which loops (forever - until cancelled via a cancellation token if required) over the channel output via its IAsyncEnumerable
- ie, await foreach (var msg in myUnboundedChannel.ReadAllAsync())