Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Some new great features in .NET 4.5 framework

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 1.02k
    Comment on it

    Readers,

    .Net Framework 4.5 came up with lots of great features. The new features of the core framework .Net 4.5 are difficult to read and run through because it does not fit depending on what are you working currently on. Many developers skip all the features and only focus on what they need in current development. Writing about all features will not be possible but some of them are:

    1. async and await
      "async" and "await" are keywords in C#. "Async" is used with a method to indicate that the method will have await keyword. In other words, we can call this function asynchronously. "Await" is used to mark the position of code from where the task should resume after a successful completion of the thread. In other words, the return type of an asynchronous function is Task. When it finishes its execution it will complete a Task.
      Each and every asynchronous method can return three types of values i.e. Void (nothing to return), Task(one operation will perform) and Task<T> (return a task with a T type parameter) where Task is simply an implementation to IAsynchResult. In short, basic concepts are:
           1. No Main method defined the asynchronous method.
           2. No Main method cannot be call by the await keyword.
           3. If any asynchronous method does not have await keyword then it will behave like a   
               synchronous method.
           4. Properties should not be defined as asynchronous.
           5. The await keyword can not be used inside lock section.
           6. No asynchronous methods call from the try/catch block or finally block.
       
    2. Zip compression:
      Earlier .Net did not have any built-in support for implementing zip compression. Many developers were using third party code-packet/assembly/component say "DotNetZip". Now, the zip feature is available in the core framework .NET 4.5.
      First, you need to import following framework assemblies (Right click on Reference in Solution Explorer then select Framework under Assemblies from left menu and select the following name)


      CreateFromDirectory function is used to zip files from a folder as shown in the below code line:
      System.IO.Compression.ZipFile.CreateFromDirectory(@"E:\AnyFolder", @"E:\ZipName.zip");

      ExtractToDirectory function is used to unzip a zip file as shown in the below code line:

      System.IO.Compression.ZipFile.ExtractToDirectory(@"E:\ZipName.zip", @"E:\UnzipFolder");
    3. Regex timeout
      "Regex" is used to validate the data and it is commonly the preferred way of doing validations. As the length increases a regex takes more time to evaluate. In other words, the time taken to evaluate rises exponentially with the number of characters.
      Due to a long time is taken while evaluating, it can be exploited by hackers. A hacker can make application hang forever by putting a really long malicious string. In the core framework .NET 4.5, there is timeout property in regex which can be used to not go application in a loop forever.
      The signature is
      public Regex(string pattern, RegexOptions options, TimeSpan matchTimeout);

       
    4. Improved start-up performance using profile optimization
      When a .NET applications run first time, it runs slow because JIT(Just In Time) compiler translates half compiled IL code to native machine code. To slow down the start-up time, the “profile optimization” has been introduced by .NET 4.5.
      Profile is a file which has the list of methods that will need during application start-up. So when the application starts, JIT runs and start translating methods reading from  "profile" file into machine/native code.
      Note: Profile Optimization is enabled by default for ASP.NET 4.5 and Silverlight 5 applications.
    5. Garbage collector (GC background cleanup)
      A real heavy task in a .NET an application is garbage collector. when the garbage collector runs for cleanup, all the application threads are suspended. To thread suspended problem, server GC was introduced. This thread works in the background and keeps cleaning.
      Due to double GC threads running, the main application threads are less suspended. To enable server GC, we need to use the gcServer XML tag and enable it to true.
      <configuration>
         <runtime>
            <gcServer enabled="true"/>
         </runtime>
      </configuration>

       

    6. Set default culture to App Domain
      In order to set culture in previous versions of .Net, I need to set culture in every thread. For example-

      CultureInfo culInfo = new CultureInfo("us-US");
      Thread.CurrentThread.CurrentCulture = culInfo ;
      Thread.CurrentThread.CurrentUICulture = culInfo ;

      In .Net 4.5, we can set culture at the app domain level and all the threads inside that appdomain will inherit that culture as shown below:

      CultureInfo culture = CultureInfo.CreateSpecificCulture("us-US");
      CultureInfo.DefaultThreadCurrentCulture = culture;


       

    7. Array support more than two gigabyte size

    8. Unicode support for console

    Some new great features in .NET 4.5 framework

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: