Channels ▼


What's New in .NET Framework 4.5

Support for Timeouts in Regular Expression Evaluations

.NET Framework 4.5 introduces a new constructor for the System.Text.RegularExpressions.Regex class that accepts a TimeSpan matchTimeout parameter to establish a timeout for the regular expression resolution. When you specify a value for the new matchTimeout parameter, if the regular expression engine doesn't resolve the regular expression in the specified time, it will throw a RegexMatchTimeoutException exception. This way, when you have very complex regular expressions, you have an easy way to establish a timeout and you don't have to use complex workarounds to generate your own timeout mechanisms.

The following code uses the new constructor with a 1000 milliseconds TimeSpan parameter to establish a 1,000 milliseconds timeout:

var regex = new Regex(

The read-only property MatchTimeout provides you the time out interval specified in the aforementioned constructor. If you didn't specify a value, the default value is Regex.InfiniteMatchTimeout, and therefore, will run with no time out.

Support for Unicode 6.0.0 in Culture-Sensitive Sorting and Casing Rules on Windows 8

.NET Framework 4.5 still includes its own string comparison data that implements Unicode 5.0.0. However, things change when you use .NET Framework 4.5 on Windows 8; it delegates culture-sensitive sorting and casing rules for string comparison to the operating system.

Windows 8 implements Unicode 6.0.0, and therefore, casing, normalization, sorting, and Unicode character information on this operating system conforms to this Unicode version instead of the default Unicode 5.0.0. (If you want more information about Unicode 6.0.0, you can read the details about this major version of the Unicode Standard). You must take that into account whenever you use the Sort and Compare methods with strings and you deploy to Windows 8.

Simple Default Culture Definition for an Application Domain

If you worked with multithreaded applications in previous .NET Framework versions and you had to share the same culture with all the worker threads, you already know some workarounds to do that, such as passing a CultureInfo instance to each new ParameterizedThreadStart delegate.

.NET Framework 4.5 finally allows you to set both the culture and the UI culture for all threads in an application domain by just assigning a CultureInfo instance to the following two static properties of the System.Globalization.CultureInfo class:

  • DefaultThreadCurrentCulture
  • DefaultThreadCurrentUICulture

For example, the following two lines of code set both the culture and the UI culture to en-US (the code assumes that you import types defined in System.Globalization):

CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture("en-US");

This way, all the threads created after the previously shown code will use en-US for both the culture and the UI culture. You can easily verify that by checking the values for the following two properties in any thread (and they will have the same value):

  • System.Threading.Thread.CurrentThread.CurrentCulture.Name
  • System.Threading.Thread.CurrentThread.CurrentUICulture.Name

Because tasks use underlying threads, the setting also applies to any task you create. This way, you can easily set the desired culture with two simple lines of code and then forget about the issue in your entire application domain.

Internationalized Domain Names in Windows 8 Apps

When you use .NET Framework 4.5 on Windows 8, the System.Globalization.IdnMapping class supports the 2008 version of the IDNA (short for Internationalized Domain Names in Applications) standard as defined in RFC 5891.

The IdnMapping class supports the use of non-ASCII characters for Internet domain names and provides methods to encode and decode domain name labels. When run on Windows 8, the methods handle particular sets of characters by using the 2008 version of the IDNA standard. However, when you execute them on other Windows versions, the methods use the 2003 version of the IDNA standard, as defined in RFC 3490.

If you work with the IdnMapping class or you are planning to do so, take into account the possible differences when handling particular sets of characters when deploying to Windows 8.

In this first article, I've provided a brief overview of some of the important global improvements introduced in .NET Framework 4.5 that affect the CLR. In the next article, I'll provide a detailed overview of the most useful new features and improvements included in ASP.NET MVC 4 and ASP.NET 4.5, with examples of real-life usage.

Gaston Hillar is a long-time Windows programmer and a frequent contributor to Dr. Dobb's.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.