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

  • SEARCH
  • Home
  • 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 7491025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:49:02+00:00 2026-05-29T15:49:02+00:00

I want enqueue a list of tasks and then perform on certain event. Code:

  • 0

I want enqueue a list of tasks and then perform on certain event. Code:

internal class MyClass
{
    private Queue<Task> m_taskQueue;

    protected MyClass()
    {
        m_taskQueue = new Queue<Task>();
    }

    public delegate bool Task(object[] args);

    public void EnqueueTask(Task task)
    {
        m_taskQueue.Enqueue(task);
    }

    public virtual bool Save()
    {
        // save by processing work queue
        while (m_taskQueue.Count > 0)
        {
            var task = m_taskQueue.Dequeue(); 
            var workItemResult = task.Invoke();

            if (!workItemResult) 
            {
                // give up on a failure
                m_taskQueue.Clear();
                return false;
            }                
        }
        return true;
    }
}

Each delegate task may have their own list of parameters: Task(object[] args). My question is how to pass the parameter to each task for the task queue?

  • 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-05-29T15:49:20+00:00Added an answer on May 29, 2026 at 3:49 pm

    Okay, now we have a bit more information, it sounds like your EnqueueTask method should actually look like this:

    public void EnqueueTask(Task task, object[] values)
    

    Right?

    For starters I would avoid using the name Task, which is already part of the core of .NET 4 and will become very prominent in .NET 5. As Joshua said, you’ve basically got a Func<object[], bool>.

    Next, you could keep two lists – one for the delegates and one for the values, but it’s easier just to keep a Queue<Func<bool>> like this:

    private readonly Queue<Func<bool>> taskQueue = new Queue<Func<bool>>();
    
    
    public void EnqueueTask(Task task, object[] values)
    {
        taskQueue.Enqueue(() => task(values));
    }
    

    Then the rest of your code will actually work “as is”. The lambda expression there will capture values and task, so when you invoke the Func<bool>, it will supply those values to the original delegate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check if an object is in a Queue before I enqueue
Want the function to sort the table by HP but if duplicate HPs then
Want to code a key pad for an calculator. What I want to make
I want to synchronize one queue among two threads. Such as one thread performs
I want to implement a timeout on the execution of tasks in a project
I have a queue in which I can enqueue different threads, so I can
I want to do a breadth first search of a tree using a Queue
I am attempting make a simulator class that will use a Queue to add
I want to put all elements of a String array into a Queue(Of String).
I want to share a Queue data structure between all the users of my

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.