-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
26 lines (19 loc) · 1.01 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Channel.CreateUnboundedPrioritized Method
// https://learn.microsoft.com/en-us/dotnet/api/system.threading.channels.channel.createunboundedprioritized?view=net-9.0
// [API Proposal] Channel.CreateUnboundedPrioritized #62761
// https://github.com/dotnet/runtime/issues/62761
// Concurrent collection with priority
// https://stackoverflow.com/questions/23470196/concurrent-collection-with-priority
using System.Threading.Channels;
var channel = Channel.CreateUnboundedPrioritized<(int priority, string message)>();
// Write sample messages
await channel.Writer.WriteAsync((2, "Emergency service dispatch"));
await channel.Writer.WriteAsync((1, "Routine check: Blood pressure measurement"));
await channel.Writer.WriteAsync((3, "Heart attack alert!"));
await channel.Writer.WriteAsync((3, "Fire alarm!"));
channel.Writer.Complete();
// Read and process messages based on priority
await foreach (var item in channel.Reader.ReadAllAsync())
{
Console.WriteLine($"Processing: {item.message} (Priority: {item.priority})");
}