本文整理汇总了C#中System.IO.Stream.BeginWrite方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.Stream.BeginWrite方法的具体用法?C# System.IO.Stream.BeginWrite怎么用?C# System.IO.Stream.BeginWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Stream
的用法示例。
在下文中一共展示了System.IO.Stream.BeginWrite方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: write
public override void write(byte[] buffer, int offset, int size,
ResultHandler rh)
{
if (mResponse != null)
throw new Exception("HTTP write");
if (mStream == null)
{
mRequest.BeginGetRequestStream(
new AsyncCallback(delegate(IAsyncResult ar)
{
mStream = mRequest.EndGetRequestStream(ar);
mStream.BeginWrite(buffer, offset, size,
new AsyncCallback(WriteCallback), rh);
}), rh);
return;
}
mStream.BeginWrite(buffer, offset, size,
new AsyncCallback(WriteCallback), rh);
}
示例2: Copy
/// <summary>
/// Transfers an entire source stream to a target
/// </summary>
/// <param name="source">
/// The stream to read
/// </param>
/// <param name="target">
/// The stream to write
/// </param>
/// <returns>
/// The total number of bytes transferred
/// </returns>
public Int32 Copy(Stream source, Stream target)
{
var copied = 0;
var bufferIdx = 0;
// start an initial dummy write to avoid
// a null test within the copy loop
var writer = target.BeginWrite(this.buffers[1], 0, 0, null, null);
for (; ; )
{
// read into the current buffer
var buffer = this.buffers[bufferIdx];
var reader = source.BeginRead(buffer, 0, buffer.Length, null, null);
// complete the previous write and the current read
target.EndWrite(writer);
var read = source.EndRead(reader);
if (read == 0)
break;
copied += read;
// start the next write for the completed read
writer = target.BeginWrite(buffer, 0, read, null, null);
// swap the buffer index for the next read
bufferIdx = (bufferIdx + 1) % 2;
}
return copied;
}