Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Queue Enqueue & Dequeue new Task?

Posted on 2014-11-01
2
Medium Priority
?
122 Views
Last Modified: 2014-11-04
I think part of my code is correct, just unsure how to Dequeue and run each Task. The problem is the Task never start. Here's what I got so far:

Queue<Task> queue = new Queue<Task>();

queue.Enqueue(new Task( () => ImportPartsList(excelFile)));

 while (queue.Count > 0)
 {
       Task.Run(() => queue.Dequeue()); //this does not start...
 };

public async Task<int> ImportEnglish(ExcelQueryFactory excelFile)
{
     AutoPartsEntities context = new AutoPartsEntities();
 
    foreach(var part in excelFile)
    {
         Parts parts = new Parts
         {
               Name = parts.Name
               Number = parts.Number
         };
          context.English.Add(parts);
          await context.SaveChangesAsync();
    }
}
0
Comment
Question by:WorknHardr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
Vel Eous earned 2000 total points
ID: 40418317
Try:
 while (queue.Count > 0)
  {
        Task.Run(() => queue.Dequeue().Start());
  };

Open in new window

0
 

Author Closing Comment

by:WorknHardr
ID: 40423273
I actually got it running like this:
       queue.Dequeue().Start()
thx
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question