c# - How to write mutually exclusive methods and Dispose? -


in short -- think of threading.timer , specialized method dispose taking waithandle parameter. in case have make 1 step further, have write regular, parameterless, yet awaiting, dispose.

the story

let's have type foo implementing such interface:

interface ifoo : idisposable {   void action1();   task action2async(); } 

the user of type foo can call action1 , @ same time action2 , @ same time dispose.

when dispose called should mark current instance disposed , wait current actions end. should proceed disposing.

regular methods should check if instance disposed , if yes, should silently quit or throw exception -- point should not proceed actual actions.

the idea

i figured out, bool flag , countdownevent should suffice -- when method called increase counter, on exit decrease it, , when implementing dispose call wait -- tell me if methods finished executing.

but here catch, countdownevent idiposable, should dispose too, won't able use in methods.

ok, write custom type wrapping countdownevent , since need memory barrier use readerwriterlockslim. but... readerwriterlockslim idisposable well.

sure, use regular lock methods calls , dispose call ratio n:1.

question

so how write mutually exclusive methods , dispose?


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -