Solved

Queue Enqueue & Dequeue new Task?

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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