Solved

Queue Enqueue & Dequeue new Task?

Posted on 2014-11-01
2
94 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:
Tchuki 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now