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 8889473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:16:18+00:00 2026-06-14T22:16:18+00:00

So I want to queue some actions to be invoked. A little background: trying

  • 0

So I want to queue some actions to be invoked.

A little background: trying to send requests using Webclient but apparantly it doesn’t allow very long URLS (upward of 2000 characters) and found the upper bound for that value in my system is around 40 items (43 to be exact). So I need to split the Webclient requests into sets of 40~ and have decided to do so using a Queue.

Here is the code:

  public void some_method()
        int num = 40; // readonly variable declared at top but put here for clarity
        String hash = "";
        Queue<Action> temp_actions = new Queue<Action>();
        foreach (ItemViewModel item in collection)
        {
            num--;
            hash += "&hash=" + item.Hash; // Add &hash + hash to hash

            if (num == 0)
            {
                // Change status for these 40 items
                temp_actions.Enqueue(() => auth.change_status_multiple(status, hash));

                // Reset variables
                num = 40;
                hash = "";
            }
        }

        // Enqueue the last action for the rest of the items
        // Since "num == 0" doesn't cater for leftovers
        // ie. 50 items and 40 in first set, 10 left (which will be enqueued here)
        temp_actions.Enqueue(() => auth.change_status_multiple(status, hash));


        // Start the change status process
        temp_actions.Dequeue().Invoke();

        actions = temp_actions;
    }

    public Queue<Action> actions { get; set; }

    // Event handler for when change_status_multiple fires its event for finish
    private void authentication_MultipleStatusChanged(object sender, EventArgs e)
    {
        if (actions.Count > 0) // Check if there are actions to dequeue
            actions.Dequeue().Invoke();
    }

But when it comes to runtime, hash will be “”.
For example, I have 50 items, 40 will be in the first action enqueued, then 10 in the second, however the hash String for the first set is “”. Why is that? I would’ve thought that upon enqueuing the action into the Queue it would keep whatever values for the variables I supplied at that time.

I debugged my code and upon enqueuing the first set, hash is correct, but when it goes to reset the variables num and hash, hash is changed for the first set (inside the queue) to “”.

Is there anyway around this?

Thanks.

  • 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-14T22:16:19+00:00Added an answer on June 14, 2026 at 10:16 pm

    You’re a victim of deferred execution… You’re capturing scope of hash in the delegate on the following line:

    temp_actions.Enqueue(() => auth.change_status_multiple(status, hash));
    //...
    hash = "";  //happens before delegate above has executed
    

    then immediately clearing hash to “”.

    When the delegate runs, hash has already been cleared.

    To fix, take a local copy of hash

    var hashCopy = hash;
    temp_actions.Enqueue(() => auth.change_status_multiple(status, hashCopy));
    //...
    hash = "";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to setup a serialized task queue using NSOperationQueue but I'm a little
I'm using the DownloadManager to queue up some downloads I'm making but running into
I'm trying to queue up some TWRequest calls using NSInvocationOperation. It seems to add
I want to create windows service which recieves via some queue tasks to run
I want to send a message whenever RabbitMQ creates or deletes a queue, exchange
Using C# ASP.NET I want to program a queue. I want to have X
I have a Queue with some data. If I want to retrieve 5 bytes
I need to set up a queue system using some SQL tables, like the
I'm trying to do some image processing on iPhone. I'm using http://developer.apple.com/library/ios/#qa/qa2010/qa1702.html to capture
I have a message queue where i add some emails. I want to extract

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.