Setting Default Global Timeout for Regular expressions

By | October 18, 2013

In my previous post, I mentioned about the capability of specifying a Timeout while executing a Regular expression. Sometimes, when your application is totally developed, and it would be a heck to change every single code which uses regular expression to specify a timeout. Sometimes the Regular expression is parsed inside an external assembly. In such cases, you can set a Global Default Timeout per appdomain which will indicate the default timeout of execution per appdomain.

To do this :

AppDomain.CurrentDomain.SetData("REGEX_DEFAULT_MATCH_TIMEOUT",TimeSpan.FromMilliseconds(200));

The data will specify the Default timeout for every regular expression running on the current Appdomain to be 200 milliseconds.

The Default timeout can be overridden by specifying another timeout when calling the Regex.

I hope this would come helpful.

Thanks for reading