Skip to content

Instantly share code, notes, and snippets.

@grumpydev
Forked from thecodejunkie/gist:5235939
Last active December 15, 2015 09:09
Show Gist options
  • Save grumpydev/5236032 to your computer and use it in GitHub Desktop.
Save grumpydev/5236032 to your computer and use it in GitHub Desktop.
if (!this.stream.CanSeek)
{
var tcs = new TaskCompletionSource<Stream>();
var buffer =
new MemoryStream((int)this.stream.Length);
this.stream.CopyTo(buffer, (source, destination, ex) =>
{
if (ex != null)
{
tcs.SetException(ex);
}
else
{
tcs.SetResult(destination);
}
});
var task = tcs.Task;
// ^^ pull this out into a method that returns tcs.task
task.Wait();
if (task.IsFaulted)
{
throw new InvalidOperationException("Unable to copy stream", task.Exception);
}
this.stream = task.Result.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment