本文整理汇总了C#中Pipe.ReadTextAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Pipe.ReadTextAsync方法的具体用法?C# Pipe.ReadTextAsync怎么用?C# Pipe.ReadTextAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pipe
的用法示例。
在下文中一共展示了Pipe.ReadTextAsync方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TimeoutTest
public void TimeoutTest()
{
var pipe = new Pipe {OutputStream = {ReadTimeout = 0}};
Assert.Throws<TimeoutException>(() => pipe.OutputStream.ReadByte());
pipe.WriteText(new string('a', 2048));
Assert.AreEqual(new string('a', 2048), pipe.ReadTextAsync(2048).Result);
}
示例2: SimpleTest
public void SimpleTest()
{
var pipe = new Pipe();
pipe.WriteText("abc");
Assert.AreEqual("abc", pipe.ReadTextAsync(3).Result);
pipe.WriteText("1");
pipe.WriteText("2");
pipe.WriteText("3");
Assert.AreEqual("123", pipe.ReadTextAsync(3).Result);
var asyncRead = pipe.ReadTextAsync(100);
Assert.AreEqual(false, asyncRead.Wait(TimeSpan.FromSeconds(.01)),
asyncRead.IsCompleted ? "Found: " + (asyncRead.Result ?? "null") : "not complete");
pipe.WriteText("x");
Assert.AreEqual(false, asyncRead.Wait(TimeSpan.FromSeconds(.01)),
asyncRead.IsCompleted ? "Found: " + (asyncRead.Result ?? "null") : "not complete");
pipe.WriteText(new string('y', 100));
Assert.AreEqual(true, asyncRead.Wait(TimeSpan.FromSeconds(5)),
asyncRead.IsCompleted ? "Found: " + (asyncRead.Result ?? "null") : "not complete");
Assert.AreEqual("x" + new string('y', 99), asyncRead.Result);
}
示例3: TestCancel
public void TestCancel()
{
var pipe = new Pipe();
var cancellationTokenSource = new CancellationTokenSource();
var asyncRead = pipe.ReadTextAsync(1, cancellationTokenSource.Token);
Assert.AreEqual(false, asyncRead.Wait(TimeSpan.FromSeconds(.01)));
cancellationTokenSource.Cancel();
Assert.AreEqual(true, asyncRead.ContinueWith(_ => { }).Wait(TimeSpan.FromSeconds(5)));
Assert.AreEqual(true, asyncRead.IsCanceled);
pipe.WriteText("aaa");
Assert.AreEqual("aa", pipe.ReadTextAsync(2).Result);
asyncRead = pipe.ReadTextAsync(1, cancellationTokenSource.Token);
Assert.AreEqual(true, asyncRead.ContinueWith(_ => { }).Wait(TimeSpan.FromSeconds(5)));
Assert.AreEqual(true, asyncRead.IsCanceled);
}
示例4: TestPartialWriteDoesNotTimeout
public void TestPartialWriteDoesNotTimeout()
{
var pipe = new Pipe {InputStream = {WriteTimeout = 0}, OutputStream = {ReadTimeout = 1000}};
pipe.SetFixedLength();
var text = Enumerable.Repeat((byte) 't', 3*Pipe.ByteBufferSize).ToArray();
var asyncWrite = pipe.InputStream.WriteAsync(text, 0, text.Length);
Assert.AreEqual(false, asyncWrite.Wait(TimeSpan.FromSeconds(.01)));
Assert.AreEqual(new string(text.Select(b => (char) b).ToArray()), pipe.ReadTextAsync(text.Length).Result);
}
示例5: TestConcurrentReads
public void TestConcurrentReads()
{
var pipe = new Pipe();
var asyncRead = pipe.ReadTextAsync(1);
Assert.Throws<InvalidOperationException>(() => pipe.OutputStream.ReadByte());
pipe.InputStream.Close();
Assert.AreEqual(true, asyncRead.Wait(TimeSpan.FromSeconds(5)));
}
示例6: TestCloseReadSide
public void TestCloseReadSide()
{
var pipe = new Pipe();
pipe.WriteText("abc");
Assert.AreEqual("ab", pipe.ReadTextAsync(2).Result);
pipe.OutputStream.Close();
Assert.Throws<ObjectDisposedException>(() => pipe.OutputStream.ReadByte());
var largeBytes = new byte[10*1024];
var initialMemory = GC.GetTotalMemory(forceFullCollection: true);
for (var i = 0; i < int.MaxValue/1024; ++i)
{
pipe.InputStream.Write(largeBytes, 0, largeBytes.Length);
}
var finalMemory = GC.GetTotalMemory(forceFullCollection: true);
Assert.IsTrue(finalMemory - initialMemory < 10*largeBytes.Length,
"final = " + finalMemory + " initial = " + initialMemory);
Assert.Throws<ObjectDisposedException>(() => pipe.OutputStream.ReadByte());
pipe.InputStream.Close();
}
示例7: TestCloseWriteSide
public void TestCloseWriteSide()
{
var pipe = new Pipe();
pipe.WriteText("123456");
pipe.InputStream.Close();
Assert.Throws<ObjectDisposedException>(() => pipe.InputStream.WriteByte(1));
Assert.AreEqual("12345", pipe.ReadTextAsync(5).Result);
Assert.AreEqual(null, pipe.ReadTextAsync(2).Result);
pipe = new Pipe();
var asyncRead = pipe.ReadTextAsync(1);
Assert.AreEqual(false, asyncRead.Wait(TimeSpan.FromSeconds(.01)));
pipe.InputStream.Close();
Assert.AreEqual(true, asyncRead.Wait(TimeSpan.FromSeconds(5)));
}
示例8: TestPartialWriteDoesNotCancel
public void TestPartialWriteDoesNotCancel()
{
var pipe = new Pipe();
var cancellationTokenSource = new CancellationTokenSource();
pipe.WriteText(new string('a', 2*Pipe.ByteBufferSize));
var asyncRead = pipe.ReadTextAsync(1);
Assert.AreEqual(true, asyncRead.Wait(TimeSpan.FromSeconds(5)));
Assert.AreEqual("a", asyncRead.Result);
pipe.SetFixedLength();
var bytes = Enumerable.Repeat((byte) 'b', Pipe.ByteBufferSize).ToArray();
var asyncWrite = pipe.InputStream.WriteAsync(bytes, 0, bytes.Length, cancellationTokenSource.Token);
Assert.AreEqual(false, asyncWrite.Wait(TimeSpan.FromSeconds(.01)));
cancellationTokenSource.Cancel();
Assert.AreEqual(false, asyncWrite.Wait(TimeSpan.FromSeconds(.01)));
asyncRead = pipe.ReadTextAsync((3*Pipe.ByteBufferSize) - 1);
Assert.AreEqual(true, asyncRead.Wait(TimeSpan.FromSeconds(5)));
Assert.AreEqual(
new string('a', (2*Pipe.ByteBufferSize) - 1) + new string('b', Pipe.ByteBufferSize),
asyncRead.Result);
}