コード例 #1
0
ファイル: sample.cs プロジェクト: logicz/multythread
 private void ClearList(IProjectListItemService service)
 {
     using (var scope = new TransactionScope())
     {
         service.DeleteItemsByList(listId);
         service.BeginTransactionAndCommit(scope);
     }
 }
コード例 #2
0
ファイル: sample.cs プロジェクト: logicz/multythread
        private void AddNewItems(IProjectListItemService service, HashSet <Guid> portfolioProjectIds)
        {
            var order = 0;
            var skip  = 0;

            while (true)
            {
                var projectIds = portfolioProjectIds.Skip(tickCount * skip++).Take(tickCount);

                if (projectIds.Count() == 0)
                {
                    break;
                }
                using (var scope = new TransactionScope())
                {
                    var items = new List <ProjectListItem>();

                    foreach (var newProjectId in projectIds)
                    {
                        items.Add(new ProjectListItem
                        {
                            ProjectListId = listId,
                            ProjectId     = newProjectId,
                            Order         = order++
                        });
                    }

                    service.CreateItems(items);
                    service.BeginTransactionAndCommit(scope);

                    lock (locker)
                    {
                        updatedCount += tickCount;
                        Monitor.PulseAll(locker);
                    }
                }
            }
        }