Solved

Queue Enqueue & Dequeue new Task?

Posted on 2014-11-01
2
111 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 500 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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

728 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