I absolutely agree with the general advice in this thread that this is generally inadvisable.
That said, for the sake of it, the ScriptManager
class is your entry point to the list of running threads in 8.1/your best source of programmatic access.
In 8.3 the web API has the corresponding functionality that's available in 8.1 but with the ability to authenticate via API tokens - so you could list running scripts and issue terminate requests via system.net.httpClient
as another option.