Esempio n. 1
0
        public void Task()
        {
            var actions = new List <Action>();

            List <WebManageMenus> list = new List <WebManageMenus>();

            List <WebManageMenus> list1 = new List <WebManageMenus>();
            List <WebManageMenus> list2 = new List <WebManageMenus>();
            List <WebManageMenus> list3 = new List <WebManageMenus>();

            actions.Add(() =>
            {
                var db = new Test_Code_FirstEntities();
                list1.AddRange(db.WebManageMenus.ToList());
            });
            actions.Add(() =>
            {
                var db = new Test_Code_FirstEntities();

                list2.AddRange(db.WebManageMenus.ToList());
            });
            actions.Add(() =>
            {
                var db = new Test_Code_FirstEntities();
                list3.AddRange(db.WebManageMenus.ToList());
            });
            Parallel.Invoke(actions.ToArray());
            list.AddRange(list1);
            list.AddRange(list2);
            list.AddRange(list3);
        }
Esempio n. 2
0
        public void TaskLock()
        {
            var actions = new List <Action>();

            List <WebManageMenus> list = new List <WebManageMenus>();
            var db = new Test_Code_FirstEntities();

            actions.Add(() =>
            {
                lock (lockObj)
                    list.AddRange(db.WebManageMenus.ToList());
            });
            actions.Add(() =>
            {
                lock (lockObj)
                    list.AddRange(db.WebManageMenus.ToList());
            });
            actions.Add(() =>
            {
                lock (lockObj)
                    list.AddRange(db.WebManageMenus.ToList());
            });
            Parallel.Invoke(actions.ToArray());
        }