CKTIS / C#
System.Threading.Channels.ChannelWriter: praktična referenca
System.Threading.Channels.ChannelWriter: praktična referenca: ChannelWriter<T> zapisuje elemente i dovršava kanal preko TryComplete ili Complete.
Verzija: .NET API; verified against .NET 10 reference surface
Sintaksa
System.Threading.Channels.ChannelWriter /* select a documented member or constructor */ChannelWriter zapisuje elemente i dovršava kanal preko TryComplete ili Complete.
Koristite TryWrite za brzi pokušaj ili WriteAsync kada treba backpressure.
Nakon dovršetka daljnji zapisi nisu dopušteni; jedna komponenta treba biti vlasnik dovršetka.
TryWrite može vratiti false za pun ili zatvoren kanal.
Cijeli program doista koristi System.Threading.Channels.ChannelWriter; točno očekivani stdout jest 7.
Primjeri
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());
Rezultat
7
Cijeli program doista koristi `System.Threading.Channels.ChannelWriter`; točno očekivani stdout jest `7`.