コード例 #1
0
        public async Task StartStopStart()
        {
            await using var pipe = new SingleConnectionPipeServer <string>("test");
            await pipe.StartAsync();

            await pipe.StopAsync();

            await pipe.StartAsync();
        }
コード例 #2
0
        public async Task DoubleStartWithSameName()
        {
            await using var pipe1 = new SingleConnectionPipeServer <string>("test");
            await pipe1.StartAsync();

            await using var pipe2 = new SingleConnectionPipeServer <string>("test");

            await Assert.ThrowsExceptionAsync <IOException>(async() => await pipe2.StartAsync());
        }
コード例 #3
0
        public async Task ClientConnectTest()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(1));
            await using var client            = new SingleConnectionPipeClient <string>(nameof(ClientConnectTest));
            await using var server            = new SingleConnectionPipeServer <string>(nameof(ClientConnectTest));

            await server.StartAsync(cancellationToken : cancellationTokenSource.Token);

            await client.ConnectAsync(cancellationTokenSource.Token);
        }
コード例 #4
0
        public async Task DoubleStartWithSameName_CommonDispose()
        {
            // ReSharper disable once UseAwaitUsing
            using var pipe1 = new SingleConnectionPipeServer <string>("test");
            await pipe1.StartAsync();

            // ReSharper disable once UseAwaitUsing
            using var pipe2 = new SingleConnectionPipeServer <string>("test");

            await Assert.ThrowsExceptionAsync <IOException>(async() => await pipe2.StartAsync());
        }
コード例 #5
0
        public static async Task DataSingleTestAsync <T>(List <T> values, Func <T, string>?hashFunc = null, IFormatter?formatter = default, TimeSpan?timeout = default)
        {
            using var cancellationTokenSource = new CancellationTokenSource(timeout ?? TimeSpan.FromSeconds(15));

            const string pipeName = "data_test_pipe";

            await using var server = new SingleConnectionPipeServer <T>(pipeName, formatter ?? new BinaryFormatter())
                        {
                            WaitFreePipe = true
                        };
            await using var client = new SingleConnectionPipeClient <T>(pipeName, formatter: formatter ?? new BinaryFormatter());

            await DataTestAsync(server, client, values, hashFunc, cancellationTokenSource.Token);
        }