正则表达式超时退出机制

原来正则表达式也会出现死循环,比如 我有两个方法 Method1, Main 。在 Method1 中写了一段正则表达式,这个表达式有出现死循环的可能。在 Main方法中调用了 Method1, 这个时候会出现程序一直无法退出的情况。解决的方式就是在 Main方法中,调用 Method1之前,设置一个Timeout时间:

AppDomain.CurrentDomain.SetData("REGEX_DEFAULT_MATCH_TIMEOUT", TimeSpan.FromSeconds(10));
mdOutput = htmlConverter.ConvertFile(htmlFile);

原文地址:https://www.cnblogs.com/qixue/p/7998237.html