Skip to content

Instantly share code, notes, and snippets.

@behnammohammadi
Last active May 2, 2023 18:14
Show Gist options
  • Save behnammohammadi/7b99a63cadc9511c58721b0cb77475e8 to your computer and use it in GitHub Desktop.
Save behnammohammadi/7b99a63cadc9511c58721b0cb77475e8 to your computer and use it in GitHub Desktop.
var cancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(30)).Token;
lock (_lock)
{
if (cancellationToken.IsCancellationRequested)
throw new TimeoutException();
// critical section - crawling
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment