Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //When I run this method, it is used in Task.WhenAny() with more such instances (I'm trying to tap into streams in proxy to log what's flowing).
- //This method throws IndexOutOfRangeException on readable[i].CopyToAsync(outputStreams[i]) - Debugger shows value of 'i' in time of execution is 2 (outputStreams.Length is 2).
- //Shouldn't lambda exception store the value of 'i' from time of declaration, instead of finding the current value (which might not exist already)?
- public static Task MultiplyStream(this Stream inputStream, params Stream[] outputStreams)
- {
- var splitStream = new ReadableSplitStream(inputStream);
- Stream[] readable = new Stream[outputStreams.Length];
- Task[] tasks = new Task[outputStreams.Length];
- for (int i = 0; i < outputStreams.Length; i++)
- {
- readable[i] = splitStream.GetForwardReadOnlyStream();
- tasks[i] = Task.Run(() => readable[i].CopyToAsync(outputStreams[i]));
- }
- splitStream.StartReadAHead();
- return Task.WhenAll(tasks);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement