使用C# 4.0
特性我想要封裝函數的通用包裝並向它們添加TimeOut
參數。在C#4.0中將'TimeOut'參數添加到'Func <>'
例如,我們有一個像功能:使用
T DoLengthyOperation()
Func
我們:
Func<T>
這是一件好事,並調用函數甚至Sync
(Invloke
)或Async
(BeginInvoke
)。 現在想想TimeOut
被添加到這個行爲,如果DoLengthyOperation()
在指定的時間內返回,我們有true
返回,否則false
。
喜歡的東西:
FuncTimeOut<in T1, in T2, ..., out TResult, int timeOut, bool result>
你問的是如何實現它或簽名應該是什麼? – SLaks 2010-12-15 18:15:49
[Implement C#Generic Timeout](http://stackoverflow.com/questions/299198/implement-c-generic-timeout) – Xaqron 2010-12-19 11:07:35