Setting Default Global Timeout for Regular expressions

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

DON'T MISS OUT!
Subscribe To Newsletter For your Daily Development Tips and Tricks  

 Best Tips & Tricks on Microsoft Technology Platform 

Invalid email address
We promise not to spam you. You can unsubscribe at any time.
Abhishek Sur

Abhishek Sur is a Microsoft MVP since year 2011. He is an architect in the .NET platform. He has profound theoretical insight and years of hands on experience in different .NET products and languages. He leads the Microsoft User Group in Kolkata named KolkataGeeks, and regularly organizes events and seminars in various places for spreading .NET awareness. He is associated with the Microsoft Insider list on WPF and C#, and is in constant touch with product group teams. He blogs at http://www.abhisheksur.com His Book : Visual Studio 2012 and .NET 4.5 Expert Development Cookbook. Follow Abhishek at Twitter : @abhi2434