c# - Understanding Streams and their lifetime (Flush, Dispose, Close) -


Note: I have already read the following two questions:

I am coding in C #

  1. Almost all code samples, which use currents, dispute (). Flush (),. Close () is almost always called.
    • In the concept of a stream, what is accomplished?
    • If I do not settle a stream which I store in a variable, then should my application be touched somewhere?
    • Why do I need to call any of these tasks? I have seen code samples that do not do and still work (without breaking clear )

I currently In my application, I am creating a class that has a primary method (it is called GetStream () ) which gives a stream through myWebRequest.GetResponse (). GetResponseStream ()

gives the primary method GetStream () a stream object which can be used for any operation One stream (streamreader, bitmap) is required.

To handle manually .getStream () caller What is one way of automatically streaming the stream after your last use (garbage collection?) Without compelling? This?

You can probably tell, my questions are unclear and general, my understanding of the streams is not concrete, so a link for those subsidiaries who can offer a more in-depth look at currents than some such questions, they are appreciated. Dismissing a single stream closes it (and possibly does nothing else.) Closing a stream, it is flushed, And related to the stream The release any resources, such as file handling takes any buffered data to flush a stream that has not been written yet, and writes it immediately; Some streams use buffering internally so that small updates can be made for relatively expensive resources such as disk file or network pipe.

Set up the close or on most streams , or your code is incorrect because the garbage collector comes as long as the underlying resource for someone else (Which knows how long it will take.) Disposes is preferred as a matter of course; It is expected that you will settle all disposable items in C #. You probably do not have to call flush in most circumstances.

In C #, it is idiotic to call dzpaj call using block, which is syntactic sugar for the end block, Which finally resolves, such as:

 using  (file stream stream = new filestream (path)) {//. ..}  

is similar to the function

  file stream stream; {Stream = try new filestream (path); // ...} Finally {if (stream! = Tap) stream. Dishes (); }  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -