且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

中止 roslyn 脚本执行

更新时间:2023-12-05 09:48:58

除了你启动一个单独的进程并杀死它(为了避免 Thread.Abort() 的标准陷阱),那就是尽你所能.鉴于脚本代码可能或多或少是任意的,真的没有比这更好的选择了.只需要您的脚本来执行 Thread.Sleep(Timeout.Infinite) 并且脚本引擎无法恢复它.

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.