CKTIS / C#
System.Threading.Channels.ChannelWriter: riferimento pratico
System.Threading.Channels.ChannelWriter: riferimento pratico: ChannelWriter<T> scrive elementi e completa il canale tramite TryComplete o Complete.
Versione: .NET API; verified against .NET 10 reference surface
Sintassi
System.Threading.Channels.ChannelWriter /* select a documented member or constructor */ChannelWriter scrive elementi e completa il canale tramite TryComplete o Complete.
Usa TryWrite per un tentativo rapido o WriteAsync quando serve backpressure.
Dopo il completamento non sono consentite altre scritture; un solo componente deve possedere il completamento.
TryWrite può restituire false per un canale pieno o chiuso.
Il programma completo usa realmente System.Threading.Channels.ChannelWriter; lo stdout esatto atteso è 7.
Esempi
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());
Risultato
7
Il programma completo usa realmente `System.Threading.Channels.ChannelWriter`; lo stdout esatto atteso è `7`.