Skip to content

Instantly share code, notes, and snippets.

View gist:10ce9806d97551b8e4a89b4e2d7b9132
There are several ways to do that, but first some facts:
- your code is executed by some thread, if you did not start more of them, then probably by the main thread of the application
- that isPrime function is probably executed by 1 specif thread that may get stuck in that method for a longer time
- it's hard to tell a thread to stop doing it's piece of work if that piece of work is not designed to be stoppable
Regarding last point: it seems easy - you can just kill the thread (unless it's THE main thread) or you can call thread.Abort(),
but both methods are dangerous, and in most cases that's a bad idea, and explaining that is another story.
So, let's first focus on "not designed to be stoppable".