If this field is static you do not need to get rid of it , it (true) will have the same lifetime as your application. I do not see this, let's move on.
The correct way to handle IDisposable is to get rid of it. I think we need a good reason not to do this.
Use a different lock:
I think it’s best to use Monitor or another lock that will have a bonus to simplify your code. ConcurrentDictionary and other wireframe classes seem to use this approach.
You are worried about locks, but I'm not sure if ReaderWriterLockSlim allowed, the only real solution is to hold fewer locks and hold them for less time.
Do not position:
This requires justification. Can you demonstrate the performance you need?
If you have several of these objects that are durable, well, not all disposable items are equally weighty (this is not like leaving an open Word document), you will probably be able to handle it. As stated, what is the point of managing all these milliseconds before the application closes anyway. I believe that the IDisposable destructor is designed to handle situations when the object is not placed, although you cannot be sure when or even if it is called.
If you have a long live application with a lot of short-lived customs of this class, however, you may have problems. You bake on your assumptions about using your code, just keep in mind.
source share