Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / C#

System.Threading.Channels.ChannelWriter: praktická referencia

System.Threading.Channels.ChannelWriter: praktická referencia: ChannelWriter<T> zapisuje prvky a dokončuje kanál pomocou TryComplete alebo Complete.

Verzia: .NET API; verified against .NET 10 reference surface

Syntax

System.Threading.Channels.ChannelWriter /* select a documented member or constructor */

ChannelWriter zapisuje prvky a dokončuje kanál pomocou TryComplete alebo Complete.

Použite TryWrite na rýchly pokus alebo WriteAsync pri potrebe backpressure.

Po dokončení nie sú ďalšie zápisy povolené; dokončenie má vlastniť iba jeden komponent.

TryWrite môže vrátiť false pre plný alebo zatvorený kanál.

Úplný program skutočne používa System.Threading.Channels.ChannelWriter; presne očakávaný stdout je 7.

Prí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ýsledok

7

Úplný program skutočne používa `System.Threading.Channels.ChannelWriter`; presne očakávaný stdout je `7`.

Zdroje