CKTIS / C#
System.Threading.Channels.ChannelWriter: praktická reference
System.Threading.Channels.ChannelWriter: praktická reference: ChannelWriter<T> zapisuje prvky a dokončuje kanál pomocí TryComplete nebo Complete.
Verze: .NET API; verified against .NET 10 reference surface
Syntaxe
System.Threading.Channels.ChannelWriter /* select a documented member or constructor */ChannelWriter zapisuje prvky a dokončuje kanál pomocí TryComplete nebo Complete.
Použijte TryWrite pro rychlý pokus nebo WriteAsync při potřebě backpressure.
Po dokončení nejsou další zápisy povoleny; dokončení má vlastnit jen jedna komponenta.
TryWrite může vrátit false pro plný nebo zavřený kanál.
Úplný program skutečně používá System.Threading.Channels.ChannelWriter; přesně očekávaný stdout je 7.
Příklady
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
var channel = Channel.CreateUnbounded<int>();
ChannelWriter<int> writer = channel.Writer; writer.TryWrite(7);
Console.WriteLine(await channel.Reader.ReadAsync());
Výsledek
7
Úplný program skutečně používá `System.Threading.Channels.ChannelWriter`; přesně očekávaný stdout je `7`.