Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8322093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:15:41+00:00 2026-06-08T23:15:41+00:00

All, I have a generic method called TaskSpin , in this method I launch

  • 0

All, I have a generic method called TaskSpin, in this method I launch a Task with an ascociated continutation

public TaskSpin(Func asyncMethod, object[] methodParameters)
{
    ...
    asyncTask = Task.Factory.StartNew<bool>(() => 
        asyncMethod(uiScheduler, methodParameters));

    asyncTask.ContinueWith(task =>
    {
        // Finish the processing update UI etc.
    }
    ...
}

The problem is now that I want to run multiple methods using TaskSpin, but I need to restrict the methods to run one-at-a-time. So foreach row in some DataGridView I want to do something like

foreach (DataGridViewRow row in this.DataGridViewUrg.Rows)
    TaskSpin(Run(DrgDataRowInfo(row.Index)));

However, in the above the TaskSpin method will exit immediately causing TaskSpin to spin off the next method on yet another thread. This is no good as the Run method write to a common set of files. What is the best way to queue these jobs?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:15:43+00:00Added an answer on June 8, 2026 at 11:15 pm

    You could implement your own task queue and just keep processing the queue after each task is complete until it’s empty e.g.

    using TaskPair = KeyValuePair<Func, object[]>;
    ...
    
    private Queue<TaskPair> taskQueue;
    ...
    
    // generate the queue of tasks
    this.taskQueue = new Queue<TaskPair>(this.DataGridViewUrg.Rows);
    foreach (DataGridViewRow row in this.DataGridViewUrg.Rows)
    {
        var task = new TaskPair(Run(DrgDataRowInfo(row.Index)), /* params */);
        this.taskQueue.Enqueue(task);
    }
    // initiate queue processing
    ProcessNextTask();
    
    ....
    private void ProcessNextTask()
    {
        try
        {
            var item = this.taskQueue.Dequeue();
            TaskSpin(item.Key, item.Value);
        }
        catch(InvalidOperationException)
        {
            // queue is empty
        }   
    }
    
    ....
    // Execute task and process next in queue (if applicable)
    public TaskSpin(Func asyncMethod, object[] methodParameters)           
    {            
        ...           
        asyncTask = Task.Factory.StartNew<bool>(() =>            
            asyncMethod(uiScheduler, methodParameters));           
    
        asyncTask.ContinueWith(task =>           
        {           
            // Finish the processing update UI etc.
            ProcessNextTask();           
        }  
        ...                 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method: public static TEventInvocatorParameters Until <TEventInvocatorParameters, TEventArgs>(this TEventInvocatorParameters p, Func<TEventArgs,
Using SubSonic3, I have this generic method (thanks to linq guy, James Curran): public
If I have two generic lists, List, and I want to merge all the
I have three classes that all have a static function called 'create'. I would
I have a form[method=get] which has a number of checkboxes all have the same
I have a masterpage file which is called Masterpage.master which works fine with all
I have a function called GetUserByOpenId I don't want to be using this function
I am working on a project where all of our object have a standard
I have a generic method in my repository which updates a property common to
I have a file called myConstants.h that I use to put all the constants

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.