中止 roslyn 脚本执行 [英] Abort roslyn script execution

查看:58
本文介绍了中止 roslyn 脚本执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为通过 Roslyn 执行的脚本实现超时机制,所以我需要一种方法来中止脚本执行.到目前为止,我找到的唯一解决方案是在线程内执行脚本并终止它,但这显然是一个有缺陷的解决方案.

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?

推荐答案

除了你启动一个单独的进程并杀死它(为了避免 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.

这篇关于中止 roslyn 脚本执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆