March, 2010

  • Wriju's BLOG

    .NET Framework 4.0 Newbie : File.ReadLines

    • 1 Comments

    In .NET Framework 4.0 instead of you using File.ReadAllLines() use ReadLines() to get a better performance. Question is why? File.ReadLines() uses IEnumerable to get the lines. Unlike File.ReadAllLines() it does not first read full files and the starts reading if you have implemented the iteration. Also File.ReadAllLines() does not implement MoveNext().

     

    But there is a catch, if you test your application to compare through sampling you may find File.ReadAllLines() is performing faster. As reading a bigger chunk at a time is faster that reading line by line. Also File.ReadLines() does not read anything unless you iterate it. So the time span between opening a file and start reading is actually nominal compared to File.ReadAllLines().

     

    Use File.ReadLines() is always better and consider it for VERY large files.

     

    Interesting observation

     

    static void Main(string[] args)

    {

        Stopwatch sw = new Stopwatch();

     

        sw.Start();

        CallingReadLines();

     

        //CallingReadAllLines();

        sw.Stop();

        string sTime1 = sw.ElapsedMilliseconds.ToString();

     

        Console.WriteLine("Time taken in Milliseconds : {0}", sw.ElapsedMilliseconds.ToString() );

           

    }

     

     

    private static void CallingReadAllLines()

    {

        string[] data = File.ReadAllLines(@"D:\Temp\LargeFile2.txt");

     

        foreach (var line in data)

        {

            //Console.Write(".");

            //Console.WriteLine(line);

            File.AppendAllText(@"C:\Temp\Out_LargeFile1.txt", line);

        }

    }

     

     

    private static void CallingReadLines()

    {

        IEnumerable<string> data = File.ReadLines(@"D:\Temp\LargeFile.txt");

     

        foreach (var line in data)

        {

            //Console.Write(".");

            //Console.WriteLine(line);

            File.AppendAllText(@"C:\Temp\Out_LargeFile2.txt", line);

        }

    }

     

     

    Namoskar!!!

     

  • Wriju's BLOG

    .NET Framework 4.0 Newbie : Stopwatch.Restart()

    • 0 Comments

    In .NET Framework 4.0 Stopwatch.Restart() is new addition.

     

    Stopwatch sw = new Stopwatch();

     

    sw.Start();

     

    //Do something

    //....

    //ERROR!!!

     

     

    //Then Restart the Stopwatch

    sw.Restart();

     

    Namoskar!!!

  • Wriju's BLOG

    .NET Framework 4.0 Newbie : System.Device.Location

    • 0 Comments

    In .NET Framework 4.0 using the System.Device.Location

     namespace one can easily access user’s computer’s location.

    For more detailed discussion please visit  http://msdn.microsoft.com/en-us/library/system.device.location(VS.100).aspx

    Namoskar!!!
  • Wriju's BLOG

    Free Guide Books from Microsoft

    • 0 Comments

    Over the years Microsoft is releasing Patterns and Practices books and distributing them for free. I think this one as great community effort and is continue to evolve. When I started writing code in .NET I always used to carry them with me. You cannot ask for more if you have them with you.

    In its home page at MSDN you will find the structure http://msdn.microsoft.com/en-us/library/ms998572.aspx

    patterns and practices offerings

    There are a few to come along with revisions and can be found at http://msdn.microsoft.com/en-us/practices/bb232643.aspx

    Few HOT releases in 2009 are

    Composite Application Guidance for WPF and Silverlight (October 2009)
    The Composite Application Guidance for WPF and Silverlight is designed to help you more easily build enterprise-level Windows Presentation Foundation (WPF) and Silverlight client applications. This guidance will help you design and build flexible composite client applications.

    Microsoft Application Architecture Guide: 2nd Edition (October 2009)
    The guide is intended to help developers and solution architects design and build effective, high quality applications using the Microsoft platform and the .NET Framework more quickly and with less risk; it provides guidance for using architecture principles, design principles, and patterns that are tried and trusted. The guidance is presented in sections that correspond to major architecture and design focus points. It is designed to be used as a reference resource or to be read from beginning to end. This guide is also available as a book from Microsoft Press (ISBN 9780735627109)

    Developing SharePoint Applications (August 2009)
    This guidance helps solution architects and software developers build applications using SharePoint. The guide covers areas such as fundamental design and development decisions, enterprise qualities, flexible content oriented approaches, and LOB integration. It provides reusable components to help with logging, repositories, configuration, service location, and event driven site creation. Two reference implementations demonstrate a partner extranet (using MOSS) and a training management application (using WSS).

    The complete catalog can be found at http://msdn.microsoft.com/en-us/practices/bb190351.aspx.

    List of guides which are not valid at http://msdn.microsoft.com/en-us/practices/bb190351.aspx#Retired

    Namoskar!!!

  • Wriju's BLOG

    Microsoft’s Official Blog – Read to know what’s next?

    • 0 Comments

    Read and subscribe http://blogs.technet.com/microsoft_blog/

    Namoskar!!!

  • Wriju's BLOG

    Steve Ballmer talking about Cloud

    • 0 Comments

    Watch it out here http://www.microsoft.com/presspass/presskits/cloud/VideoGallery.aspx

    image

    were_all_in_home 

    Namoskar!!!

  • Wriju's BLOG

    .NET Framework 4.0 Newbie : String.IsNullOrWhiteSpace

    • 0 Comments

    In .NET Framework 4.0 we have String.IsNullOrWhiteSpace.

    String sData = " ";

     

    if (String.IsNullOrWhiteSpace(sData))

    {

        Console.WriteLine("Nothing to do");

    }

     

    This would help us to determine whether to work with a string without calling additional Trim() method.

    Namoskar!!!

  • Wriju's BLOG

    .NET Framework 4.0 Newbie : Addition to Environment.SpecialFolder enum

    • 1 Comments

    In .NET Framework 4.0 we have few new useful Environment variables,

    AdminTools

    CDBurning

    CommonAdminTools

    CommonDesktopDirectory

    CommonDocuments

    CommonMusic

    CommonOemLinks

    CommonPictures

    CommonProgramFilesX86

    CommonPrograms

    CommonStartMenu

    CommonStartup

    CommonTemplates

    CommonVideos

    Fonts

    LocalizedResources

    MyVideos

    NetworkShortcuts

    PrinterShortcuts

    ProgramFilesX86

    Resources

    SystemX86

    UserProfile

    Windows

    In addition to that Environment.GetFolder path now has one additional overload which accepts Environment.SpecialFolder enum as parameter.

    image

    These address a broad range of requirements like x64 OS to Win 7 onwards profiles.

    Namoskar!!!

  • Wriju's BLOG

    Installing Visual Studio 2010 RC in Windows XP SP3

    • 1 Comments

    Very helpful article http://blogs.msdn.com/psiman/archive/2010/03/02/installing-visual-studio-2010-rc1-on-xp-sp3.aspx

     

    Namoskar!!!

     

  • Wriju's BLOG

    .NET Framework 4.0 Newbie : SortedSet<T>

    • 0 Comments

    In .NET Framework 4.0 we have a new class called SortedSet<T>. This helps us to sort the elements without explicitly we implementing any sort method.

    var sSet = new SortedSet<int> { 2, 4, 6, 8, 9, 1, 3, 5, 7 };

     

    //Getting directly the sorted output

    foreach (int iVal in sSet)

    {

        Console.WriteLine(iVal);

    }

     

    This would give you output in the following order,

     

    1

    2

    3

    4

    5

    6

    7

    8

    9

     

    Also we can get Min and Max

    //Min & Max

    Console.WriteLine("Max = {0}", sSet.Max);

    Console.WriteLine("Min = {0}", sSet.Min);

     

    This could be helpful wherever we predict to call a Sort function while working with the collection.

    Namoskar!!!

  • Wriju's BLOG

    .NET Framework 4.0 Newbie : StringBuilder.New

    • 0 Comments

    In .NET Framework 4.0 we have an option to clear StringBuilder class. Unlike previous versions where we used to write StringBuilder.Length = 0 to clean, now we can implement a new method called Clear().

     

    var sBulder = new StringBuilder();

     

    sBulder.Append("Anyhting");

    sBulder.Append("Again another");

     

    //Previous approach to clear up StringBuilder

    sBulder.Length = 0;

     

    //New approach to clean string builder

    sBulder.Clear();

     

     

    Namoskar!!!

Page 1 of 1 (11 items)