Solved

Queue Enqueue & Dequeue new Task?

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

615 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