Created
September 4, 2012 12:34
-
-
Save clupasq/3620792 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
[Test] | |
public void ComputeResultWithTimeout() | |
{ | |
var task = Task.Factory.StartNew(() => ComputeResult("bla")); | |
//task.Wait(0999); | |
task.Wait(1000); | |
if (task.IsCompleted) | |
Console.WriteLine("OK, got: " + task.Result); | |
else | |
Console.WriteLine("Get a dummy fucking result: 666"); | |
} | |
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