code_junkie

Implementing IAsyncResult explicitly

Nov 13th, 2011
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. public class Concurrent<T> {
  2. private ManualResetEvent _resetEvent;
  3. private T _result;
  4.  
  5. public Concurrent(Func<T> f) {
  6. ThreadPool.QueueUserWorkItem(_ => {
  7. _result = f();
  8. IsCompleted = true;
  9. if (_resetEvent != null)
  10. _resetEvent.Set();
  11. });
  12. }
  13.  
  14. public WaitHandle WaitHandle {
  15. get {
  16. if (_resetEvent == null)
  17. _resetEvent = new ManualResetEvent(IsCompleted);
  18. return _resetEvent;
  19. }
  20.  
  21. public bool IsCompleted {get; private set;}
  22. ...
Add Comment
Please, Sign In to add comment