-
-
Save tetri/7a00c9e06410fc57fa0c8eba1da192c1 to your computer and use it in GitHub Desktop.
C# Timeout implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ComputeResultWithTimeout() | |
{ | |
var task = Task.Factory.StartNew(() => ComputeResult("vrau")); | |
//task.Wait(0999); | |
task.Wait(1000); | |
if (task.IsCompleted) | |
Console.WriteLine($"oba! {task.Result}"); | |
else | |
Console.WriteLine("oh não! tempo esgotado..."); | |
} | |
public int ComputeResult(string someParameter) | |
{ | |
Thread.Sleep(1000); | |
return 42; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment