Exemple #1
0
        static void Main(string[] args)
        {
            TaskFactory taskFactory = new TaskFactory();
            List <Task> taskList    = new List <Task>();

            for (int i = 0; i < 5; i++)
            {
                taskList.Add(taskFactory.StartNew(() => { Singleton singleton = Singleton.CreateInstance(); }));
            }
            Console.ReadKey();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //数据和任务的并行
            Parallel.For(1, 10, l =>
            {
                Console.WriteLine("任务ID:{0},线程ID:{1}", Task.CurrentId, Thread.CurrentThread.ManagedThreadId);


                //获取单例
                Singleton singleton = Singleton.CreateInstance();

                //获取简单单例
                Single single = Single.instance;
            }
                         );

            Console.Read();
        }