Array of threads in c sharp

I usually declare the threads inside the using statement to make sure the thread is configured correctly when I finish with it, and therefore I will not mistakenly name it when I'm outside the used block.

Some examples here: MSDN using documentation help

How to use using statement with array of threads? Would it be tantamount to declaring an array outside the try / catch / finally block and calling each method to delete the stream in the finally block?

Finally, how to check if the threads are configured correctly?

+3
source share
3 answers

I would create a new object that contains threads. Something like this (not fully specified):

class StreamHolder : IDisposable
{
  List<Stream> Streams {get;}

  public void  Dispose()
  {
      Streams.ForEach(x=>x.Dispose()):
  }
}

- using, . - finally, , , , ,

+5

, using using.

, Dispose ( , IDisposable, ). finally.

, . Dispose, , .

+3

using() - , , . , .

, , , , using(), , encocassing finally .

, , Stream - , , /, IDisposable , Close/Dispose, .

+2

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


All Articles