Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IAsyncResult result;
- Action action = () =>
- {
- Console.WriteLine("Action started!!");
- Thread.Sleep(2000); // Assume a long running operation here which might take more than 15000 ms as well, resulting in timeout
- Console.WriteLine("Now the action got completed!!");
- };
- result = action.BeginInvoke(null, null);
- if (result.AsyncWaitHandle.WaitOne(15000))
- {
- Console.WriteLine("Timeout didn't happen!!");
- }
- else
- {
- Console.WriteLine("Timeout happened!!");
- }
- Console.WriteLine("Main thread continues to work!!");
Add Comment
Please, Sign In to add comment