#StackBounty: #c# #multithreading #list #tfs #wiql A list containing 2 more lists works slow in looping can i use Thread to make this f…

Bounty: 50

This is my code in which a list contains 2 more lists where the WorkItem collection contains a large number of records such as 7,000 it takes 10 min. Is there any way to make it faster and in case it’s deciding the workItem type if it’s a bug, task or product backlog item. Please tell me how to make the looping faster. It’s taking 10 min to loop 7,000 records can we use threading to make it faster?

    var workItemList = new List<WorkItemViewModel>();

            for (int i = 0; i < workItemCollection.Count; i++)
            {
                var workItem = workItemCollection[i];

                if (workItem.Type.Name == "Product Backlog Item")
                {
                    var model = new WorkItemViewModel()
                    {


                        FID = (workItem.WorkItemLinks.Count > 0) ? ((workItem.WorkItemLinks[0].LinkTypeEnd.Name.ToString() != "Child") ? workItem.WorkItemLinks[0].TargetId : 0) : 0,

                        ID = workItem.Id,
                        Name = workItem.Title,
                        State = workItem.State,

                        priorty = Convert.ToInt32(workItem.Fields["Priority"].Value),
                        //   Size =(int) workItem.Fields["Size"].Value ,
                        Size = Convert.ToInt32(workItem.Fields["Effort"].Value),

                        StoryPoints = Convert.ToInt32(workItem.Fields["Story Points"].Value),
                        DoneStatus = workItem.Fields["Done Status"].Value.ToString(),
                        StoryOwner = workItem.Fields["Story Owner"].Value.ToString(),
                        Assignedto = workItem.Fields["Assigned To"].Value.ToString(),
                        StoryAuthor = workItem.Fields["Story Author"].Value.ToString(),
                        IterationPath = workItem.IterationPath
                    };

                    workItemList.Add(model);
                }
                else
                {
                    switch (workItem.Type.Name)
                    {
                        case "Task":
                            var task = new TFSTask()
                            {
                                Storyid = (workItem.WorkItemLinks.Count > 0) ? workItem.WorkItemLinks[0].TargetId : 0,
                                ID = workItem.Id,
                                name = workItem.Title,
                                //activity = workItem.Fields["MyCompany.Activity"].Value.ToString(),
                                //start = (DateTime?)workItem.Fields["MyCompany.ActivityStart"].Value,
                                //due = (DateTime?)workItem.Fields["MyCompany.ActivityFinish"].Value,
                                status = workItem.State,
                                IterationPath = workItem.IterationPath,
                                Assignedto = workItem.Fields["Assigned To"].Value.ToString(),

                                priorty = Convert.ToInt32(workItem.Fields["Priority"].Value),
                                effort = Convert.ToInt32(workItem.Fields["effort"].Value),
                                Completed = Convert.ToInt32(workItem.Fields["Completed"].Value)

                            };
                            if (task.Storyid != 0)
                            {
                                workItemList.Last().Tasks.Add(task);
                            }


                            break;
                        case "Bug":
                            var bug = new TFSIssue()
                            {
                                Storyid = (workItem.WorkItemLinks.Count > 0) ? workItem.WorkItemLinks[0].TargetId : 0,
                                ID = workItem.Id,
                                Name = workItem.Title,
                                //start = (DateTime?)workItem.Fields["MyCompany.ActivityStart"].Value,
                                //due = (DateTime?)workItem.Fields["MyCompany.ActivityFinish"].Value,
                                State = workItem.State,
                                IterationPath = workItem.IterationPath,
                                Assignedto = workItem.Fields["Assigned To"].Value.ToString(),

                                priorty = Convert.ToInt32(workItem.Fields["Priority"].Value),
                                effort = Convert.ToInt32(workItem.Fields["effort"].Value),
                                // Completed = Convert.ToInt32(workItem.Fields["Completed"].Value)
                            };
                            if (bug.Storyid != 0)
                            {
                                workItemList.Last().Issues.Add(bug);
                            }
                            break;



                        default:
                            break;
                    }
                }
            }

 public class WorkItemViewModel
    {
        public string Name { get; set; }
        public int ID { get; set; }

        public string State { get; set; }
        // public DateTime? due { get; set; }
        public int priorty { get; set; }
        public int Size { get; set; }
        //  public int effort { get; set; }
        public int StoryPoints { get; set; }
        public string DoneStatus { get; set; }
        public string StoryOwner { get; set; }
        public string Assignedto { get; set; }
        public string StoryAuthor { get; set; }
        public string IterationPath { get; set; }
        public int FID { get; set; }
        public List<TFSIssue> Issues { get; set; }
        public List<TFSTask> Tasks { get; set; }

        public WorkItemViewModel()  // Added a public constructor
        {
            Issues = new List<TFSIssue>();
            Tasks = new List<TFSTask>();

        }

    }


Get this bounty!!!

Leave a Reply