コード例 #1
0
ファイル: Program.cs プロジェクト: quocthang0507/CSharp
        static void ThreadProc(object state)
        {
            LargeObject large = lazyLargeObject.Value;

            // IMPORTANT: Lazy initialization is thread-safe, but it doesn't protect the
            //            object after creation. You must lock the object before accessing it,
            //            unless the type is thread safe. (LargeObject is not thread safe.)
            lock (large)
            {
                large.Data[0] = Thread.CurrentThread.ManagedThreadId;
                Console.WriteLine("Initialized by thread {0}; last used by thread {1}.",
                                  large.InitializedBy, large.Data[0]);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: quocthang0507/CSharp
        static LargeObject InitLargeObject()
        {
            LargeObject large = new LargeObject(Thread.CurrentThread.ManagedThreadId);

            return(large);
        }