当前位置: 首页>>代码示例>>C#>>正文


C# IProgress.OnProgress方法代码示例

本文整理汇总了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;
		}
开发者ID:divyang4481,项目名称:lextudio,代码行数:44,代码来源:FileHelper.cs

示例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;
			}
		}
开发者ID:divyang4481,项目名称:lextudio,代码行数:36,代码来源:FileHelper.cs


注:本文中的IProgress.OnProgress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。