Lazy thread for C # /. NET

Does anyone know about lazy stream in .net? IOW, I want to create a method like this:

public Stream MyMethod() {
    return new LazyStream(...whatever parameters..., delegate() {
        ... some callback code.
    });
}

and when my other code calls MyMethod () to return the stream, it will not actually do any work until someone really tries to read from the stream. The usual way would be to force MyMethod to take the stream parameter as a parameter, but this will not work in my case (I want to pass the returned MVC stream to FileStreamResult).

To clarify what I'm looking for, you need to create a multi-level series of transformations, so

Database result = (converted to) => byte stream = (chained to) => GZipStream = (transferred) => FileStreamResult constructor.

The result set can be huge (GB), so I don’t want to cache the result in a MemoryStream, which I can pass to the GZipStream constructor. Rather, I want to get from a result set, since GZipStream is requesting data.

+3
source share
3 answers

This answer ( fooobar.com/questions/611783 / ... ) is referenced in this article on how to write a custom thread class.

To quote an answer:

The producer writes the data to the stream, and the consumer reads. There is a buffer in the middle so that the producer can write a little ahead. You can determine the size of the buffer.

To indicate the source source:

ProducerConsumerStream Stream. . . Head Tail.

Head Tail, , , . , Tail Head, , .

, .

-1

- , , . , , ( " ", , ).

Stream, , Read, , . Read, CanRead, CanWrite CanSeek.

+3

Stream System.IO.Stream, Read.

, , . - , , , . , .

Unfortunately, this will take more than the implementation of the reading method, and your delegate will not cover the other necessary methods.

0
source

Source: https://habr.com/ru/post/1722508/


All Articles