问题
I'd like to implement timeout mechanism for scripts, executed through Roslyn, so I need a way to abort a script execution. The only solution I found so far, is executing the script inside a thread and terminating it, but it's obviously a flawed solution.
Is there a better way to do this?
回答1:
Other than you launching a separate process and killing that instead (to avoid the standard pitfalls of Thread.Abort()
), that's the best you can do. Given the script code can be more or less arbitrary, there really couldn't be a better option. All it takes is your script to do Thread.Sleep(Timeout.Infinite)
and there's nothing the scripting engine could do to recover that.
来源:https://stackoverflow.com/questions/38866383/abort-roslyn-script-execution