Skip to content

Instantly share code, notes, and snippets.

@clupasq
Created September 4, 2012 12:34
Show Gist options
  • Save clupasq/3620792 to your computer and use it in GitHub Desktop.
Save clupasq/3620792 to your computer and use it in GitHub Desktop.
C# Timeout implementation
[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