本文整理汇总了C#中System.IO.Stream.BeginRead方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.Stream.BeginRead方法的具体用法?C# System.IO.Stream.BeginRead怎么用?C# System.IO.Stream.BeginRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Stream
的用法示例。
在下文中一共展示了System.IO.Stream.BeginRead方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public void Load(SafeUri uri)
{
if (is_disposed)
return;
//First, send a thumbnail if we have one
if ((thumb = XdgThumbnailSpec.LoadThumbnail (uri, ThumbnailSize.Large, null)) != null) {
pixbuf_orientation = ImageOrientation.TopLeft;
EventHandler<AreaPreparedEventArgs> prep = AreaPrepared;
if (prep != null)
prep (this, new AreaPreparedEventArgs (true));
EventHandler<AreaUpdatedEventArgs> upd = AreaUpdated;
if (upd != null)
upd (this, new AreaUpdatedEventArgs (new Rectangle (0, 0, thumb.Width, thumb.Height)));
}
using (var image_file = ImageFile.Create (uri)) {
image_stream = image_file.PixbufStream ();
pixbuf_orientation = image_file.Orientation;
}
loading = true;
// The ThreadPool.QueueUserWorkItem hack is there cause, as the bytes to read are present in the stream,
// the Read is CompletedAsynchronously, blocking the mainloop
image_stream.BeginRead (buffer, 0, count, delegate (IAsyncResult r) {
ThreadPool.QueueUserWorkItem (delegate {HandleReadDone (r);});
}, null);
}
示例2: GetResponseCallback
void GetResponseCallback(IAsyncResult asyncResult)
{
try
{
WebResponse = WebRequest.EndGetResponse(asyncResult);
Stream = WebResponse.GetResponseStream();
BufferOffset = 0;
Stream.BeginRead(Buffer, BufferOffset, Buffer.Length, ReadCallback, null);
}
catch(System.Exception e)
{
Exception = e;
}
}
示例3: 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;
}
示例4: startReceive
public void startReceive(IAsyncResult res)
{
try
{
download_response = (HttpWebResponse)download_request.EndGetResponse(res);
total = (int)download_response.ContentLength;
downloaded = 0;
onprogress(null, 0, total, 0);
stream = download_response.GetResponseStream();
stream.BeginRead(buffer, 0, 65536, downloading, this);
}
catch (Exception e)
{
failure("Error " + action, e);
}
}
示例5: startReceive
public void startReceive(IAsyncResult res)
{
try
{
response = (HttpWebResponse)request.EndGetResponse(res);
response_stream = response.GetResponseStream();
response_stream.BeginRead(buffer, 0, buffer.Length, downloading, this);
}
catch (Exception e)
{
failure("Error receiving response from server after upload", e);
}
}