delegates - Creating a reusable method timeout class in C# -


I am trying to create a class that calls me ways with a specified time. I have a real time-end implementation, but it's having trouble filling in a class successfully.

I have decided at this time that I take an expiration 0 - 4 argument on my methods to work with only 5 action representatives, for the purposes of this question, I have a logic of action Will use the version.

My ideal calling syntax will be something like this:

  verb & lt; Int & gt; A = new timeout action (i = & gt; i + 1) {timeout = timepace.frucesecond (10)}  

or this:

  verb & Lt; Int & gt; A = (x = & gt; x + 1) Timeout (Timepay framesconds (10)) I'm pretty sure that the first version is not possible because there is no way to come from one delegate second  delegate  It can be possible by using an extension method on type. 

"Text">

with any suggestions or ideas

Your last suggestion will be in the right way:

One final fallback will be to create a static method that is suitable Representatives take in and a delegate returns with the same signature, but with the expiration.

In other words:

  public stable action & lt; T & gt; Timeout & lt; T & gt; (This Action & lt; T & gt; Action, Timespace Timespain); Public static action & lt; T1, T2 & gt; Timeout & lt; T1, T2 & gt; (This Action & lt; T1, T2 & gt; Action, Timespace Timespain); Public Static Func & lt; T, TResult & gt; Timeout & lt; T, TResult & gt; (This fax & lt; T, tresult & gt; action, timespace timespain); Public Static Func & lt; T1, T2, TResult & gt; Timeout & lt; T1, T2, TResult & gt; (This Fax & lt; T1, T2, TResult & gt; Action, Timespace Timespain); / * Action & Lieutenant; ... & gt; And Funk & lt; ... & gt;   

You can declare a method that returns a representative and a representative , but then you lose information about the representative type (Your second example is not compiled)

Unfortunately, the following example is not valid C # - You can not use delegate as a type parameter constraint:

  Public stable TED elat timeout & lt; TDelegate & gt; (This TDelegate d, Timespan timespan) where TDIlet: Representative;  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -