BineG
BineG

Reputation: 365

How to get the count of messages in System.Threading.Channels.Channel

A simple question:

Is there any way to get the number of messages in a System.Threading.Channels.Channel instance? Seems a bit odd there doesn't seem to be any builtin way to do it?

Upvotes: 0

Views: 1058

Answers (1)

YuhZheng
YuhZheng

Reputation: 11

I believe there is a channel.Reader.Count.
Note: this is counting the existing messages in the channel, not the channel capacity.

Reference:

  1. https://learn.microsoft.com/en-us/dotnet/api/system.threading.channels.channel-2.reader?view=net-5.0#System_Threading_Channels_Channel_2_Reader
  2. https://learn.microsoft.com/en-us/dotnet/api/system.threading.channels.channelreader-1?view=net-5.0

Upvotes: 1

Related Questions