Warning: count(): Parameter must be an array or an object that implements Countable in /home/devartplus/devartplus.com/wp-content/plugins/maxblogpress-ping-optimizer/maxblogpress-ping-optimizer.php on line 455

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/devartplus/devartplus.com/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

Archive

Archive for the ‘GC’ Category

When and how to use GC.KeepAlive in .Net

August 27th, 2011 1 comment

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/devartplus/devartplus.com/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

Let’s look on the following C# code example (ignore the correctness of the code and its logic)

    /// <summary>
    /// Indicates any service Logger for example
    /// </summary>
    class MyService
    {
        public MyService(string fileName)
        {
            //Do some initializations
        }

        public static void DoSomething()
        {
            //some calculations, or logs creation
        }
    }
    //*************************************************
    /// <summary>
    /// Usage example class 
    /// </summary>
    class MyLogic
    {
        public void Foo()
        {
            //cals static method of the initialized service
            MyService.DoSomething();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            //Create our service 
            MyService myService = new MyService("temp.txt");
            //Wait here for user
            Console.ReadLine();
        }
    }

Read more…

Categories: .Net, GC Tags: ,