本文整理汇总了C#中System.Action.NullSafeInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# Action.NullSafeInvoke方法的具体用法?C# Action.NullSafeInvoke怎么用?C# Action.NullSafeInvoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Action
的用法示例。
在下文中一共展示了Action.NullSafeInvoke方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compress
public static int Compress(Stream input, Stream output, int uncompressedSize, Action<long> compressed = null)
{
Exceptions.CheckArgumentNull(input, "input");
Exceptions.CheckArgumentNull(output, "output");
Exceptions.CheckArgumentOutOfRangeException(uncompressedSize, "uncompressedSize", 0, int.MaxValue);
byte[] buff = new byte[Math.Min(32 * 1024, uncompressedSize)];
ZOutputStream writer = new ZOutputStream(output, 6);
long position = output.Position;
int readed;
while (uncompressedSize > 0 && (readed = input.Read(buff, 0, Math.Min(buff.Length, uncompressedSize))) > 0)
{
uncompressedSize -= readed;
writer.Write(buff, 0, readed);
compressed.NullSafeInvoke(readed);
}
writer.finish();
if (uncompressedSize != 0)
throw new Exception("Неожиданный конец потока.");
return (int)(output.Position - position);
}
示例2: Uncompress
public static void Uncompress(Stream input, Stream output, int uncompressedSize, byte[] buff, CancellationToken cancelationToken, Action<long> uncompressed = null)
{
Exceptions.CheckArgumentNull(input, "input");
Exceptions.CheckArgumentNull(output, "output");
Exceptions.CheckArgumentOutOfRangeException(uncompressedSize, "uncompressedSize", 0, int.MaxValue);
ZInputStream reader = new ZInputStream(input);
int readed;
while (uncompressedSize > 0 && (readed = reader.read(buff, 0, Math.Min(buff.Length, uncompressedSize))) > 0)
{
if (cancelationToken.IsCancellationRequested)
return;
uncompressedSize -= readed;
output.Write(buff, 0, readed);
uncompressed.NullSafeInvoke(readed);
}
if (uncompressedSize != 0)
throw new Exception("Неожиданный конец потока.");
}
示例3: CopyAsync
public static async Task CopyAsync(Stream input, Stream output, ManualResetEvent cancelEvent, Action<long> progress)
{
byte[] buff = new byte[32 * 1024];
int read;
while ((read = await input.ReadAsync(buff, 0, buff.Length)) != 0)
{
if (cancelEvent.WaitOne(0))
return;
await output.WriteAsync(buff, 0, read);
progress.NullSafeInvoke(read);
}
}