Guest User

Untitled

a guest
Feb 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. IAsyncResult result;
  2. Action action = () =>
  3. {
  4. Console.WriteLine("Action started!!");
  5. Thread.Sleep(2000); // Assume a long running operation here which might take more than 15000 ms as well, resulting in timeout
  6. Console.WriteLine("Now the action got completed!!");
  7. };
  8.  
  9. result = action.BeginInvoke(null, null);
  10.  
  11. if (result.AsyncWaitHandle.WaitOne(15000))
  12. {
  13. Console.WriteLine("Timeout didn't happen!!");
  14. }
  15. else
  16. {
  17. Console.WriteLine("Timeout happened!!");
  18. }
  19.  
  20.  
  21. Console.WriteLine("Main thread continues to work!!");
Add Comment
Please, Sign In to add comment