c# - Failsafe disposal in an async world -


in synchronous world, c# makes management of things disposable rather easy:

using(idisposable somedisposable=bla.bla()) {      //do our bidding } //don't worry 

however, when go async, no longer have convenience of using block. 1 of best strategies i've encountered ccr iterator allows use async code "as if synchronous". means can keep our using block in iterator handler , not bogged down in complex decision of when dispose , catching cases disposal required.

however, in many cases, invoking ccr can seem overkill, , honest, although i'm quite comfortable ccr, uninitiated can double-dutch.

so question is: other strategies exist management of one's idisposable's, when disposable objects must persist beyond immediate scope?

one approach have methods not able coexist disposal method take lock while run, , check queue objects needing disposal when finish. disposal method add queue, use tryenter try acquire lock, dispose object , delete queue if successful, or else let current holder of lock handle disposal.


Comments

Popular posts from this blog

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

apache - Add omitted ? to URLs -

php - How can I stop spam on my custom forum/blog? -