本文整理汇总了C#中IProgress.OnProgress方法的典型用法代码示例。如果您正苦于以下问题:C# IProgress.OnProgress方法的具体用法?C# IProgress.OnProgress怎么用?C# IProgress.OnProgress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IProgress
的用法示例。
在下文中一共展示了IProgress.OnProgress方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BlockRead
/// <summary>
/// Reads from a stream in small blocks
/// to enable progress-pumping.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="offset">The offset.</param>
/// <param name="length">The length.</param>
/// <param name="progress">The progress.</param>
/// <returns></returns>
public static byte[] BlockRead(
Stream stream,
int offset,
int length,
IProgress progress )
{
if ( offset != stream.Position )
{
stream.Seek( offset, SeekOrigin.Begin );
}
byte[] buffer = new byte[length];
int bytesToRead = length;
int index = offset;
while ( bytesToRead > 0 )
{
if ( progress != null )
{
progress.OnProgress(
null,
EventArgs.Empty );
}
int count = Math.Min( blockSize, bytesToRead );
stream.Read( buffer, index - offset, count );
index += count;
bytesToRead -= count;
}
return buffer;
}
示例2: BlockWrite
/// <summary>
/// Writes a buffer to a file in small blocks
/// to enable progress-pumping.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="buffer">The buffer.</param>
/// <param name="offset">The offset.</param>
/// <param name="length">The length.</param>
/// <param name="progress">The progress.</param>
public static void BlockWrite(
Stream stream,
byte[] buffer,
int offset,
int length,
IProgress progress )
{
int index = offset;
int bytesToWrite = length;
while ( bytesToWrite > 0 )
{
if ( progress != null )
{
progress.OnProgress(
null,
EventArgs.Empty );
}
int count = Math.Min( blockSize, bytesToWrite );
stream.Write( buffer, index, count );
index += count;
bytesToWrite -= count;
}
}